QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646319#7470. WBLTpiggy12360 1413ms15444kbC++206.4kb2024-10-16 22:13:082024-10-16 22:13:09

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 22:13:09]
  • 评测
  • 测评结果:60
  • 用时:1413ms
  • 内存:15444kb
  • [2024-10-16 22:13:08]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

struct node {
	ll l,r,b,id;
} p[100005],P2[100005];
ll tot=0;
vector<node> P3[100005];
ll a[100005],cnt[100005],ANS[100005],S;
const ll w=64,w2=6,w3=63,lim=100000;
unsigned ll pre[88],suf[88];
struct Bitset {
	vector<unsigned ll> vs;
	ll n;
	inline void init(ll len) {
		vs.resize((len>>w2)+4);
		n=len;
	}
	friend Bitset operator&(Bitset A,Bitset B) {
		Bitset C;
		C.init(max(A.n,B.n));
		for (ll i=0; i<=(min(A.n,B.n)>>w2); i++) {
			C.vs[i]=A.vs[i]&B.vs[i];
		}

		return C;
	}
	inline ll operator[](ll x) {
		return vs[x>>w2]>>(x&w3)&1;
	}

	inline void set(ll x,ll v) {
		vs[x>>w2]-=(vs[x>>w2]>>(x&w3)&1)<<(x&w3);
		vs[x>>w2]+=v<<(x&w3);
	}
	inline ll subcut(ll l,ll r) {
		if ((l>>w2)==(r>>w2)) {
			return ((pre[r&w3]-(!(l&w3)?0:pre[(l&w3)-1]))&vs[l>>w2])>>(l&w3);
		} else {
			return ((suf[l&w3]&vs[l>>w2])>>(l&w3))|((pre[r&w3]&vs[r>>w2])<<(w-(l&w3)));
		}
	}
	inline Bitset sub(ll l,ll r) {
		Bitset C;
		C.init(max(0ll,r-l+1));
		if (r-l+1<=0)return C;
		ll pl=l;
		for (ll i=0; i<=((r-l+1)>>w2); i++) {
			C.vs[i]=subcut(pl,min(r,pl+w-1));
			pl+=w;
		}
		return C;
	}
	inline bool any() {
		for (ll i=0; i<=(n>>w2); i+=4)if (vs[i]|vs[i+1]|vs[i+2]|vs[i+3])return 1;
		return 0;
	}
	inline void all() {
		for (ll i=0; i<(n>>w2); i++) {
			vs[i]=pre[w-1];
		}
		vs[n>>w2]=pre[n&w3];
	}
	inline ll mex() {
		ll ans=0;
		for (ll i=0; i<=(n>>w2); i++) {
			if ((~vs[i])==0){
				ans+=w;
			}else{
				ans+=__builtin_ctzll(~vs[i]);
				break;
			}
		}
		return ans;
	}
} bs,bs2[66];
ll T=0;

inline void add(ll pos) {
	cnt[a[pos]]++;
	if (cnt[a[pos]]==1) {
		bs.set(a[pos],1);
	}
}

inline void del(ll pos) {
	cnt[a[pos]]--;
	if (cnt[a[pos]]==0) {
		bs.set(a[pos],0);
	}
}

inline void add1(ll pos) {
	cnt[a[pos]]++;
	if (cnt[a[pos]]==1) {
		bs2[a[pos]%T].set(a[pos]/T,1);
	}
}

inline void del1(ll pos) {
	cnt[a[pos]]--;
	if (cnt[a[pos]]==0) {
		bs2[a[pos]%T].set(a[pos]/T,0);
	}
}

inline ll read() {
	ll x=0;
	char c=getchar();
	while(!isdigit(c))c=getchar();
	while (isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}

int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	n=read();
	for (ll i=1; i<=n; i++) {
		a[i]=read();
	}
	for (ll i=0; i<w; i++) {
		if (i==0) {
			pre[i]=(1ull<<i);
		} else {
			pre[i]=pre[i-1]+(1ull<<i);
		}
	}
	for (ll i=w-1; i>=0; i--) {
		suf[i]=suf[i+1]+(1ull<<i);
	}
	ll q;
	q=read();
	for (ll i=1; i<=q; i++) {
		p[i].l=read(),p[i].r=read(),p[i].b=read();
		p[i].id=i;
		if (p[i].b<=40) {
			P3[p[i].b].push_back(p[i]);
		} else {
			P2[++tot]=p[i];
		}
	}
	if (tot) {
		S=n/sqrt(tot)+1;
		sort(P2+1,P2+1+tot,[&](node a,node b) {
			return (a.l/S==b.l/S?(a.l/S%2?a.r>b.r:a.r<b.r):a.l<b.l);
		});
		ll L=1,R=0;
		bs.init(lim);
		for (ll i=1; i<=tot; i++) {
//		cout<<p[i].l<<" "<<p[i].r<<"------------\n";
			while (L>P2[i].l)add(--L);
			while (R<P2[i].r)add(++R);
			while (L<P2[i].l)del(L++);
			while (R>P2[i].r)del(R--);
			Bitset ans;
			ans.init(P2[i].b-1);
			ans.all();
			ll rel=lim/P2[i].b+1;
			for (ll j=1; j<=lim/P2[i].b+1; j++) {
				Bitset A=bs.sub((j-1)*P2[i].b,min(lim,j*P2[i].b-1));
				ans=ans&A;
				if (!ans.any()) {
					rel=j-1;
					break;
				}
			}
			ANS[P2[i].id]=rel;
		}
	}

	for (ll i=1; i<=w; i++) {
		if (P3[i].empty())continue;
		S=n/sqrt(P3[i].size())+1;
		T=i;
		for (ll j=0; j<=lim; j++)cnt[j]=0;
		sort(P3[i].begin(),P3[i].end(),[&](node a,node b) {
			return (a.l/S==b.l/S?(a.l/S%2?a.r>b.r:a.r<b.r):a.l<b.l);
		});
		for (ll j=0; j<i; j++) {
			bs2[j].init(lim/i);
			for (unsigned ll &k:bs2[j].vs) {
				k=0;
			}
		}
		ll L=1,R=0;
		for (ll j=0; j<P3[i].size(); j++) {
			while (L>P3[i][j].l)add1(--L);
			while (R<P3[i][j].r)add1(++R);
			while (L<P3[i][j].l)del1(L++);
			while (R>P3[i][j].r)del1(R--);
			for (ll k=0; k<P3[i][j].b; k++) {
				ANS[P3[i][j].id]=max(ANS[P3[i][j].id],bs2[k].mex());
			}
		}
	}
	for (ll i=1; i<=q; i++)cout<<ANS[i]<<"\n";
	return 0;
}

/*
2
49999 99999
1
1 2 49999
                                                                
 ■■■■■     ■■      ■■■     ■■■   ■    ■     ■     ■■■■    ■■■■  
 ■   ■■    ■■     ■  ■■   ■  ■■  ■    ■    ■■     ■  ■■  ■■  ■  
 ■    ■    ■■    ■    ■  ■    ■   ■  ■    ■■■    ■■  ■■  ■   ■■ 
 ■    ■    ■■    ■    ■  ■    ■   ■  ■     ■■    ■   ■■      ■■ 
 ■    ■    ■■    ■       ■         ■■      ■■        ■■      ■  
 ■   ■■    ■■    ■  ■■■  ■  ■■■    ■■      ■■       ■■     ■■■  
 ■■■■■     ■■    ■    ■  ■    ■    ■■      ■■      ■■        ■■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■■          ■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■      ■   ■■ 
 ■         ■■    ■■  ■■  ■■  ■■    ■■      ■■    ■       ■■  ■■ 
 ■         ■■      ■■■■    ■■■■    ■■      ■■    ■■■■■■   ■■■■  
*/

詳細信息

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 0ms
memory: 8420kb

input:

1000
233 991 831 426 140 881 289 287 957 886 561 109 305 469 961 577 683 593 277 601 181 255 100 997 161 619 632 413 987 811 357 635 99 809 888 511 945 881 261 434 851 311 21 641 508 701 661 158 696 560 577 501 951 786 909 238 546 573 617 236 270 705 786 353 651 296 353 720 261 429 855 176 977 57 50...

output:

3
3
2
4
4
0
3
2
2
2
2
2
1
4
2
2
3
3
2
2
5
3
1
2
2
2
2
1
3
3
2
3
1
3
5
2
0
4
2
1
5
2
2
2
2
2
2
2
2
2
2
6
1
3
2
1
2
2
1
0
0
2
2
2
3
2
1
3
2
2
2
3
2
4
0
2
2
2
3
3
2
2
0
2
3
2
2
2
4
1
2
2
4
3
2
2
5
3
2
2
1
1
2
2
2
6
3
2
1
2
3
1
1
0
3
3
2
2
2
1
2
2
2
3
3
3
2
4
3
2
1
5
2
4
2
1
1
2
2
3
2
2
2
3
3
2
2
1
2
2
...

result:

ok 1000 numbers

Subtask #2:

score: 30
Accepted

Test #2:

score: 30
Accepted
time: 112ms
memory: 14356kb

input:

100000
241 721 861 909 540 928 171 159 637 60 145 227 110 975 766 220 311 761 191 980 887 793 773 957 625 61 994 606 465 625 598 667 181 197 15 826 136 499 199 331 621 327 945 726 197 997 681 641 465 805 211 531 333 505 483 345 612 241 376 700 5 338 661 777 241 412 118 585 121 1 398 658 855 598 300 ...

output:

2
6
17
3
2
2
2
2
2
3
2
2
11
2
7
2
4
2
2
3
9
5
2
2
4
2
2
4
2
2
2
2
7
8
2
2
9
2
3
4
4
2
3
2
2
3
2
2
1
2
2
2
13
167
11
2
3
0
2
2
2
2
2
2
3
3
4
7
2
3
2
4
2
5
2
23
2
3
2
0
2
2
2
4
2
4
2
2
4
2
2
5
2
91
5
2
2
2
3
3
2
2
3
2
0
2
3
2
2
2
3
2
5
2
2
5
2
77
21
2
7
3
2
3
2
2
2
2
13
2
4
4
2
2
9
2
2
2
3
13
3
5
2
4
...

result:

ok 100000 numbers

Test #3:

score: 30
Accepted
time: 109ms
memory: 14500kb

input:

100000
6 8 75 85 89 8 88 56 1 64 37 6 28 16 87 74 57 51 5 72 39 85 100 54 1 97 77 40 97 95 65 56 37 13 44 23 68 49 85 79 27 57 75 81 1 26 61 45 97 31 85 61 51 37 30 53 1 51 11 57 49 22 40 67 49 85 53 89 1 97 88 57 79 6 61 61 36 75 71 53 81 91 91 1 91 1 29 67 47 81 81 37 71 14 17 26 65 59 36 7 97 77 ...

output:

5
2
4
2
4
4
4
0
6
2
2
7
8
2
3
2
4
8
2
2
2
8
2
2
2
0
4
1
3
2
2
4
10
2
3
0
2
13
2
2
3
2
2
2
5
2
3
2
0
3
6
2
0
2
3
2
3
34
2
2
7
2
2
8
2
2
10
2
0
0
2
2
2
3
2
2
2
3
2
5
2
2
2
2
2
2
5
10
34
2
2
3
3
2
3
2
2
2
2
20
4
13
4
4
2
50
5
3
2
2
10
2
3
2
3
4
2
12
3
7
12
5
2
5
3
4
2
2
3
2
2
2
2
2
2
2
4
2
2
2
2
2
0
13...

result:

ok 100000 numbers

Test #4:

score: 30
Accepted
time: 78ms
memory: 14376kb

input:

100000
6 7 6 6 1 1 9 1 7 6 3 4 6 6 5 1 8 6 6 3 2 7 1 3 6 3 9 2 1 7 6 10 7 5 7 7 3 1 1 6 1 3 3 2 5 1 9 2 1 10 3 7 1 1 7 3 4 6 5 5 10 8 7 3 9 5 4 9 5 1 2 1 10 1 7 1 9 2 9 5 1 1 9 9 1 10 7 1 6 5 3 9 3 6 10 7 6 9 7 3 9 1 1 7 6 9 5 3 4 1 9 7 9 3 8 10 1 6 7 9 4 1 5 1 1 5 1 1 6 5 7 3 9 7 7 5 6 3 4 7 6 5 5 ...

output:

2
4
2
2
2
0
0
2
0
5
2
0
2
2
2
0
3
2
0
2
2
0
2
1
3
2
4
0
0
1
2
4
2
2
0
2
0
0
2
0
2
0
4
2
2
2
2
0
2
2
3
2
2
5
4
3
0
2
2
2
3
3
2
1
2
0
1
2
2
2
4
2
2
2
0
2
4
0
2
2
3
4
2
0
3
2
2
4
2
2
0
0
4
4
1
2
2
2
3
2
2
2
0
2
2
5
0
2
4
1
2
2
2
2
2
2
0
2
2
2
2
0
4
2
2
5
0
2
4
2
2
5
2
0
2
4
2
0
4
2
2
2
2
2
0
2
5
2
4
2
...

result:

ok 100000 numbers

Subtask #3:

score: 0
Time Limit Exceeded

Test #5:

score: 40
Accepted
time: 1011ms
memory: 15168kb

input:

99917
24947 3268 49683 43610 87927 86331 16017 19557 72137 16689 28231 87819 9481 2403 18661 8145 86091 90410 54635 10896 53999 43367 95987 23733 17359 94625 81763 44331 63663 6075 20784 94229 61578 3890 95047 32681 39491 33139 51629 34573 859 31797 22897 7647 52199 17817 6311 46787 20619 81037 5374...

output:

3
7
9
5
3123
34
5
3
2
7
8
45
34
350
11
515
3
0
40
1
11
2
5
2
3
267
6
2
3
11
333
13
0
5
11
424
676
17
7
103
5
11
4
10
3
4
1
23
2
7
4
63
7
1
0
93
10
7
9
5674
16
1
16
9
141
2
1
2
18
1
6
4
1
0
714
8
18
14
3
1
4
13
5
4
1
278
6
19
130
9
7
763
3
26
5
2
1427
4
3348
389
41
11
1564
362
10
5
8
1
2271
15
18
3
3...

result:

ok 99968 numbers

Test #6:

score: 40
Accepted
time: 1413ms
memory: 15016kb

input:

99904
10367 10479 10591 10703 10815 10927 11039 11151 11263 11375 11487 11599 11711 11823 11935 12047 12159 12271 12383 12495 12607 12719 12831 12943 13055 13167 13279 13391 13503 13615 13727 13839 13951 14063 14175 14287 14399 14511 14623 14735 14847 14959 15071 15183 15295 15407 15519 15631 15743 ...

output:

12
9
342
3028
0
0
4
617
1
4
1
0
516
4
655
0
482
1
56
8
2
7
366
6
5551
3
1
102
25
648
25
19
0
1
2
2
813
261
1
33301
48
0
2
1
3
3
412
5
12
5
10
12
680
193
246
10
8
388
3
2
1
25
4
8
709
10
106
45
2
231
88
3
3
140
296
3
26
1
20
108
9
3
573
641
3
2
6
3
5551
29
9
4
10
1
6
26
2
117
2
1
6
143
1
2
276
7
31
0...

result:

ok 99924 numbers

Test #7:

score: 40
Accepted
time: 1007ms
memory: 15444kb

input:

99969
25648 25858 26068 26278 26488 26698 26908 27118 27328 27538 27748 27958 28168 28378 28588 28798 29008 29218 29428 29638 29848 30058 30268 30478 30688 30898 31108 31318 31528 31738 31948 32158 32368 32578 32788 32998 33208 33418 33628 33838 34048 34258 34468 34678 34888 35098 35308 35518 35728 ...

output:

367
3
23
26
0
4
1
5
1
50
4
0
5
324
15
529
2
5
215
25
2
36
1
1
7
1
4
1
5
1
58
265
1
2
94
11
4
102
122
9
17
17
562
271
2
0
18
3
7
3
26
5
87
3
7
1
2
172
13
5
65
5
75
1
36
13
83
1
79
260
1
758
10
29
6
6
94
26
5
529
54
1667
5
8
5
2
318
1
6
85
282
2381
1
6
124
5
2
221
75
10
28
74
39
22
128
186
5
11108
45
...

result:

ok 99968 numbers

Test #8:

score: 40
Accepted
time: 787ms
memory: 14860kb

input:

99906
36465 45696 53812 65157 8362 50390 8938 66579 26693 23509 59735 63357 37477 90628 20147 72910 99559 37162 99384 68055 41090 33886 85000 37741 67533 62838 51629 98159 34652 32219 64124 29772 82734 49142 4703 53488 34548 33792 92462 74455 72552 15702 95270 78539 95968 59919 73874 85989 75481 135...

output:

0
10
4344
1
1
5
2351
11
1199
17
1
9
49
8
8
21
58
135
3
4
9
30
21
3
331
1
232
544
65
2
5
9
6
209
540
21
7
3
4
1
24
13
4
1
132
4
4
7
3
27
1
12
15
47
4
4344
2
17
8
3
1
111
0
22
4
6
3752
108
3
3
1052
4
4
101
7
360
3
1444
2
55
3
6
3
2
73
233
114
9
52
0
13
59
2
4
13
106
8
101
5
9
6
2
6
345
1
13
3
4
5
4
18...

result:

ok 99917 numbers

Test #9:

score: 40
Accepted
time: 715ms
memory: 13252kb

input:

99966
44799 72530 81392 43798 83470 66203 36496 90621 14743 58886 57175 17632 39281 51952 84112 28506 46662 77651 3258 5736 3873 75583 60096 4179 68022 6864 52499 86228 51707 9717 33268 6141 16004 41257 12889 34449 56219 68531 41082 10477 88198 76466 4391 66838 90572 15137 16809 59816 94083 13212 42...

output:

75
3
1
1
28
110
2
4
2
3
12
5
36
3
404
2
9
27
206
11
1
2
132
6
6
17
33
1
68
10
2
3
10
1
14
4
72
3610
148
1
9
2
7
4
78
9
16
208
3
1
6
3
3
2
62
1
8
5
8
2
154
2
2
101
2
115
1
9
83
518
1
138
11
6
6
7
1
5
109
54
14743
63
5
2
7
15
130
2
3
6
209
1
4
4
6
758
4
43
1
400
5
64
14
0
9
2
9
14
5
11
3
2
15
2
2
3
25...

result:

ok 99916 numbers

Test #10:

score: 40
Accepted
time: 869ms
memory: 13872kb

input:

99963
16111 1092 30535 68250 78002 71251 53420 37707 77827 76960 96449 627 10162 53821 54943 71088 60448 37958 6279 69907 4736 35587 45691 2165 58554 68958 51294 59907 9282 44970 56859 87998 11636 35967 26608 22820 33458 54516 40680 72697 35476 12105 75861 54756 43874 67663 68941 94121 85262 68565 7...

output:

1
4
7
3
6
196
22
0
3
483
5
2
3
32
6
0
12
5
22
113
7
1
807
507
5
1
13
14
2
3
5
4
0
75
475
9
3
0
18
5
14
4
668
13
3
12
1
3
4
4
1
145
3
1695
8
3
0
794
3
2
5
1
4
2
1
0
11
0
10
4
22
3
208
1
6
18
676
3
12
150
0
6
7
1
3
2564
0
13
40
5
33
4
18
59
1020
12
3
5
2
4
2
1
3124
20
5
4
6
2
15
44
0
6
338
1
540
7
74
...

result:

ok 99939 numbers

Test #11:

score: 40
Accepted
time: 760ms
memory: 14788kb

input:

99906
82922 16337 13778 79565 79931 7193 95297 41300 6080 72632 57248 29069 77522 36602 75833 24392 58469 44033 83057 70322 57176 90650 13406 78563 88808 23651 79955 14408 20912 63836 84119 24140 74351 59504 74342 52880 67070 15911 64409 47462 5804 61739 67175 23096 48878 77999 36425 12221 16721 477...

output:

1
16
6
4
13
5
9
3
6
4
6
1
5
23
145
7
0
16
9
205
8
13
6
0
7
3
6
4
7
6
22
6
2
3
6
22
7
9
11
3
6
5
6270
6
5
5
1
2
4
5
11
4
2
5
8
3
3
8
17
6
11
32
8
6
7
6
8
9
6
5
19
3
15
13
6
5
0
4
6
7
5
23
4
8
4
4
5
5
13
5
15
8
6
6
4
64
1
9
21
6
5
14
4
4
770
20
4
581
3
25
19
9
8
5
20
9
6
2
1
5
3
6
0
5
18
1
84
5
10
27
...

result:

ok 99979 numbers

Test #12:

score: 40
Accepted
time: 772ms
memory: 14020kb

input:

99947
64197 19476 49866 50373 45603 3729 33306 80571 31965 77622 2598 23841 42345 31779 12906 76089 73389 5916 5193 71136 82686 87639 14889 96102 49224 46869 52806 37185 36615 46713 19134 43422 77526 22122 43857 16407 42516 11346 68223 8118 42753 58509 23970 14970 1647 40206 81948 24909 29232 91605 ...

output:

1
35
17
183
102
3
18
3
26
91
13
16
31
6
0
16
4
27
2
5
31
7
14
8
40
3
3
13
2
3
18
4
22
6
22
5
26
2
7
2
25
4
31
55
29
9
2
23
21
12
1
22
51
2
28
59
8
3
8
7
14
7
1
10
117
32
20
21
11
1
19
27
4
2
21
528
4
16
31
0
12
8
7
3
438
22
2
13
17
13
4
10
1
6
48
5
9
65
15
1
14
8
4
29
90
361
1
13
12
9458
3
5
4
100
1...

result:

ok 99972 numbers

Test #13:

score: 0
Time Limit Exceeded

input:

99927
29417 29457 29497 29537 29577 29617 29657 29697 29737 29777 29817 29857 29897 29937 29977 30017 30057 30097 30137 30177 30217 30257 30297 30337 30377 30417 30457 30497 30537 30577 30617 30657 30697 30737 30777 30817 30857 30897 30937 30977 31017 31057 31097 31137 31177 31217 31257 31297 31337 ...

output:


result: