QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#812384#7248. Ivan DornAuroreTL 2915ms68764kbC++232.9kb2024-12-13 14:54:332024-12-13 14:54:35

Judging History

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

  • [2024-12-13 14:54:35]
  • 评测
  • 测评结果:TL
  • 用时:2915ms
  • 内存:68764kb
  • [2024-12-13 14:54:33]
  • 提交

answer

#include<bits/stdc++.h>
//#define int long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int buf[105];
inline void print(int x,char ch=' '){
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	do{
		buf[++tot]=x%10;
		x/=10;
	}while(x);
	for(int i=tot;i;i--) putchar(buf[i]+'0');
	putchar(ch);
}
const int MAXN=5e5+5;
int n,m,B,a[MAXN],b[MAXN];

int st[MAXN][20],lg[MAXN];
inline int query(int l,int r){
	int b=lg[r-l+1];
	return max(st[l][b],st[r-(1<<b)+1][b]);
}

int ans[MAXN];
int f[MAXN],g[MAXN];
struct node{
	int l,r,id;
	node(int a=0,int b=0,int c=0){
		l=a,r=b,id=c;
	}
	bool friend operator<(const node &a,const node &b){
		return a.r<b.r;
	}
};
vector<node> qry[MAXN];

#define pr(x,y) make_pair(x,y)
#define F first
#define S second
pair<int,int> pre[MAXN],suf[MAXN];
pair<int,int> tmp1[MAXN],tmp2[MAXN];
void solve(int mid){
	sort(qry[mid].begin(),qry[mid].end());
	
	int pos=mid,mx=0;
	for(auto q:qry[mid]){
		while(pos<=q.r){
			if(suf[a[pos]].S&&query(suf[a[pos]].S,pos)<=a[pos]){
				if(pre[a[pos]]==suf[a[pos]])
					pre[a[pos]].S=suf[a[pos]].S=pos;
				else
					suf[a[pos]].S=pos;
			}
			else{
				suf[a[pos]]=pr(pos,pos);
				if(!pre[a[pos]].F) pre[a[pos]]=pr(pos,pos);
			}
			mx=max(mx,suf[a[pos]].S-suf[a[pos]].F);
			pos++;
		}
		
		int cpy=mx;
		for(int i=mid-1;i>=q.l;i--)
			tmp1[a[i]]=pre[a[i]],tmp2[a[i]]=suf[a[i]];
		
		for(int i=mid-1;i>=q.l;i--){
			if(pre[a[i]].F&&query(i,pre[a[i]].F)<=a[i]){
				if(pre[a[i]]==suf[a[i]])
					pre[a[i]].F=suf[a[i]].F=i;
				else
					pre[a[i]].F=i;
			}
			else{
				pre[a[i]]=pr(i,i);
				if(!suf[a[i]].F) suf[a[i]]=pr(i,i);
			}
			mx=max(mx,pre[a[i]].S-pre[a[i]].F);
		}
		ans[q.id]=mx;
		
		mx=cpy;
		for(int i=mid-1;i>=q.l;i--)
			pre[a[i]]=tmp1[a[i]],suf[a[i]]=tmp2[a[i]];
	}
	
	for(int i=1;i<=n;i++) pre[a[i]]=suf[a[i]]=pr(0,0);
}
signed main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=b[i]=read();
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+n+1,a[i])-b;
	
	for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
	for(int i=1;i<=n;i++) st[i][0]=a[i];
	for(int j=1;(1<<j)<=n;j++)
		for(int i=1;i+(1<<j)-1<=n;i++)
			st[i][j]=max(st[i][j-1],st[i+(1<<j-1)][j-1]);
	
	B=sqrt(n)*2;
	for(int i=1;i<=m;i++){
		int l=read(),r=read();
		if(r-l+1<=B){
			for(int j=l;j<=r;j++){
				if(f[a[j]]&&query(f[a[j]],j)<=a[j])
					g[a[j]]+=j-f[a[j]];
				else g[a[j]]=0;
				f[a[j]]=j;
				ans[i]=max(ans[i],g[a[j]]);
			}
			for(int j=l;j<=r;j++)
				f[a[j]]=g[a[j]]=0;
		}
		else{
			if((l-1)%B==0) qry[l].push_back(node(l,r,i));
			else{
				int id=((l-1)/B+1)*B+1;
				qry[id].push_back(node(l,r,i));
			}
		}
	}
	
	for(int i=1;i<=n;i+=B)
		solve(i);
	
	for(int i=1;i<=m;i++) print(ans[i],'\n');
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11844kb

input:

8 5
4 3 2 2 3 3 7 3
1 7
6 8
1 3
3 6
1 8

output:

4
0
0
1
4

result:

ok 5 number(s): "4 0 0 1 4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 15888kb

input:

1 1
1
1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 3ms
memory: 15800kb

input:

2 1
1 2
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 3ms
memory: 15956kb

input:

2 1
1 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 13880kb

input:

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

output:

1
2
2
2
0
1
0
2
0
0

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 13824kb

input:

10 10
4 10 1 4 1 1 4 1 4 10
8 10
1 7
5 9
5 9
3 7
9 10
4 10
5 10
2 3
2 8

output:

0
3
2
2
3
0
5
2
0
3

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 13968kb

input:

10 10
5 6 6 6 6 5 6 6 6 5
1 10
2 9
3 9
3 10
5 10
3 7
2 4
1 1
1 3
3 9

output:

7
7
6
6
4
4
2
0
1
6

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 17852kb

input:

10 10
8 8 8 8 8 8 8 8 8 8
3 10
6 7
3 4
3 10
2 8
6 8
9 10
9 10
2 3
1 2

output:

7
1
1
7
6
2
1
1
1
1

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 17984kb

input:

10 10
100 30 100 91 100 91 91 100 91 91
6 6
9 10
7 7
7 8
1 3
6 10
2 7
3 10
6 7
2 9

output:

0
1
0
0
2
1
2
5
1
5

result:

ok 10 numbers

Test #10:

score: 0
Accepted
time: 3ms
memory: 17984kb

input:

10 10
962186504 962186504 962186504 766659307 396032294 766659307 396032294 962186504 962186504 962186504
5 7
3 5
3 5
3 6
3 7
4 10
1 6
3 8
9 9
2 6

output:

0
0
0
2
2
2
2
5
0
2

result:

ok 10 numbers

Test #11:

score: 0
Accepted
time: 3ms
memory: 14092kb

input:

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

output:

104
827
728
149
190
375
111
224
357
245
274
120
259
284
39
475
637
126
633
33
634
186
481
426
111
396
117
304
356
241
322
17
20
39
123
182
3
29
31
559
73
377
324
428
53
499
668
808
367
384
47
269
358
38
402
295
393
46
338
506
17
94
198
420
530
30
66
111
380
0
457
75
337
250
750
209
239
319
94
603
11...

result:

ok 1000 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 13892kb

input:

1000 1000
3 6 6 4 3 4 4 6 4 3 6 6 3 6 4 6 4 3 6 4 3 4 4 4 4 4 6 4 6 3 6 4 4 4 3 6 6 6 4 4 6 6 3 3 3 3 3 3 3 3 4 3 4 3 6 3 4 4 4 6 3 4 6 6 4 4 6 6 6 3 6 3 3 6 3 3 6 6 3 4 4 6 6 3 4 3 4 6 4 4 6 6 4 6 6 6 4 3 4 4 4 3 4 6 4 3 3 4 3 3 3 6 4 6 6 4 6 4 4 6 3 4 6 3 6 3 6 3 3 4 4 3 4 6 4 3 6 4 3 3 3 3 6 3 3 ...

output:

482
52
756
335
576
463
874
388
291
117
242
38
371
547
839
737
61
758
333
61
548
49
493
210
764
429
98
656
216
340
375
554
144
51
541
729
790
64
573
598
613
149
38
101
551
534
454
400
389
769
80
240
251
212
433
418
347
21
768
576
732
394
413
17
964
360
543
652
22
104
532
774
205
73
150
279
442
151
37...

result:

ok 1000 numbers

Test #13:

score: 0
Accepted
time: 0ms
memory: 18044kb

input:

1000 1000
779655852 570687905 532375847 506607529 9891268 749503650 4098495 630571050 710512568 181451139 142356637 235702199 444046132 235702199 862838994 642274852 796797743 696114065 925197379 86797147 934824382 749503650 86797147 116251856 231651548 806725940 565701805 934824382 450170455 116251...

output:

177
7
162
173
8
646
23
23
23
162
44
350
335
350
8
51
484
44
23
7
51
350
12
51
8
335
350
311
173
2
16
23
13
51
512
48
350
5
17
311
7
8
16
162
177
8
350
44
646
23
4
350
0
16
23
345
350
465
51
23
484
162
23
162
173
19
484
646
627
646
335
7
173
350
173
335
173
16
44
1
646
335
8
16
23
162
11
335
311
646
...

result:

ok 1000 numbers

Test #14:

score: 0
Accepted
time: 0ms
memory: 18028kb

input:

1000 1000
223497770 609899281 761163089 974969758 849355373 122570654 333479794 555791305 456147841 1470121 888919173 202518003 996089108 626112455 645394653 763158420 894982852 976489314 344683769 512407665 728579480 692885294 597038354 603212111 150934581 733075341 954120597 669478556 555008488 29...

output:

1
128
1
0
128
1
128
128
4
128
0
1
0
128
0
1
0
128
128
1
0
4
128
1
0
0
0
1
0
1
0
1
128
0
1
128
1
0
1
0
0
1
128
0
0
128
0
1
128
0
1
128
128
1
128
0
0
128
1
128
1
0
1
1
1
0
4
0
1
0
4
0
1
1
1
1
128
1
0
128
0
1
0
1
128
1
128
1
1
0
0
0
0
0
1
1
1
0
0
128
0
0
0
0
0
1
0
4
128
0
0
1
0
1
128
128
0
1
1
128
1
0
...

result:

ok 1000 numbers

Test #15:

score: 0
Accepted
time: 0ms
memory: 17908kb

input:

1000 1000
217215921 880326454 184594692 756506156 217215921 520512606 54976207 520512606 520512606 756506156 166970086 520512606 184594692 184594692 166970086 217215921 184594692 120292834 880326454 166970086 54976207 880326454 77051050 166970086 520512606 184594692 54976207 217215921 166970086 5497...

output:

325
0
214
300
465
360
106
89
89
58
117
311
281
321
64
709
583
546
276
576
282
660
303
118
419
231
214
154
118
150
219
676
75
535
383
214
602
305
303
26
173
57
618
35
93
93
853
19
153
307
251
323
261
333
86
493
436
219
199
583
62
370
89
187
487
352
114
231
759
18
59
79
551
669
62
223
494
70
88
186
52...

result:

ok 1000 numbers

Test #16:

score: 0
Accepted
time: 0ms
memory: 13892kb

input:

1000 1000
417 417 417 417 916 916 417 916 417 916 417 417 916 916 916 916 916 417 417 417 417 417 916 916 417 417 916 916 417 417 417 417 916 417 916 916 417 417 417 417 916 916 916 916 916 417 916 417 417 417 916 417 417 417 916 417 916 417 417 916 417 417 916 916 916 417 916 916 916 916 417 417 41...

output:

189
394
121
455
246
282
139
248
651
51
458
121
627
210
30
143
268
192
368
564
402
66
116
433
607
721
674
685
384
19
137
524
265
691
575
652
31
4
494
417
455
776
155
694
175
316
285
368
222
81
156
4
134
130
338
99
726
48
347
113
108
140
481
529
204
333
576
545
432
777
338
186
411
336
755
90
55
654
95...

result:

ok 1000 numbers

Test #17:

score: 0
Accepted
time: 0ms
memory: 18036kb

input:

1000 1000
606 314 821 1000 722 915 916 492 747 564 144 913 606 283 719 129 140 836 16 39 829 61 387 424 531 611 825 196 896 108 474 126 916 724 73 571 846 448 997 599 462 61 964 361 79 996 202 581 14 802 489 140 72 81 75 545 110 128 672 182 603 56 305 435 178 891 615 628 456 996 597 679 547 488 562 ...

output:

38
7
0
153
358
38
358
283
75
0
153
358
38
12
75
358
12
16
153
38
0
38
7
38
12
12
12
153
38
38
26
358
26
0
26
2
358
358
358
283
153
16
75
358
7
38
358
38
153
38
153
3
38
75
358
75
75
153
0
1
75
358
283
38
24
0
153
38
0
358
153
7
0
358
38
283
358
2
283
358
283
75
75
2
358
0
12
12
358
7
12
0
358
0
0
15...

result:

ok 1000 numbers

Test #18:

score: 0
Accepted
time: 0ms
memory: 11948kb

input:

1000 1000
187649594 651382345 680851384 339717409 508102557 279098056 429593192 631009237 896514831 758598562 558386750 587499644 858393396 457964623 892038620 709766839 598925194 178689767 545134267 58868737 990204297 906185073 970703265 809163859 733923026 728811206 372232059 939172903 380756740 6...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 numbers

Test #19:

score: 0
Accepted
time: 3ms
memory: 14024kb

input:

1000 1000
162201375 366003420 261331314 574479328 305703928 692514521 905356689 623809512 162201375 445200585 324601871 546183808 243359246 546183808 455922654 479679864 604040229 243359246 935967556 623809512 692514521 533078110 623809512 259028504 511836557 479679864 196945557 178583568 761846391 ...

output:

136
364
46
483
87
331
193
477
357
372
316
32
696
99
284
194
193
0
289
401
526
161
231
482
46
766
0
219
193
264
406
107
720
13
526
145
67
605
287
6
116
52
572
434
20
455
0
217
215
142
193
372
72
815
176
405
171
510
795
264
245
387
653
243
0
890
293
621
145
416
443
237
145
356
181
533
6
18
12
262
2
10...

result:

ok 1000 numbers

Test #20:

score: 0
Accepted
time: 3ms
memory: 13944kb

input:

1000 1000
983608211 744248881 744248881 983608211 744248881 983608211 983608211 744248881 744248881 744248881 744248881 744248881 744248881 983608211 983608211 983608211 983608211 983608211 983608211 744248881 744248881 983608211 744248881 983608211 983608211 983608211 983608211 983608211 983608211 ...

output:

79
144
293
134
57
93
849
20
552
158
51
242
747
279
109
259
101
619
127
279
288
149
120
490
482
127
298
395
532
61
372
26
517
16
129
539
495
335
592
354
556
501
492
125
149
498
150
4
66
358
40
299
264
316
122
347
416
148
31
563
624
401
127
455
192
328
738
67
258
103
457
207
836
258
90
552
35
73
761
4...

result:

ok 1000 numbers

Test #21:

score: 0
Accepted
time: 680ms
memory: 35736kb

input:

200000 200000
1 10 4 10 10 4 1 1 4 1 10 4 10 1 1 4 10 1 4 10 10 1 10 1 10 10 4 1 4 10 4 1 10 4 4 4 4 1 4 4 4 4 1 4 1 1 1 1 10 10 10 4 10 4 10 10 10 4 4 1 10 4 10 10 1 10 4 1 10 1 1 10 4 4 10 1 10 4 4 1 10 1 1 4 4 4 1 4 4 10 10 10 10 10 1 10 4 4 4 4 1 10 4 1 4 10 10 4 4 10 10 4 1 1 4 4 10 4 10 1 1 10...

output:

109355
36112
26377
12389
88246
24187
30947
81166
147860
40221
106972
138597
1184
36803
102538
31699
57329
154775
7924
14731
6105
30747
137767
78758
47852
85258
11940
125556
45858
75806
148022
18073
23389
107378
86203
138992
67148
701
61740
138684
35117
53689
29491
30373
109748
76415
67262
19945
1148...

result:

ok 200000 numbers

Test #22:

score: 0
Accepted
time: 676ms
memory: 39928kb

input:

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

output:

15671
93937
14278
3299
179012
107082
44672
41773
37842
29970
67228
26661
21622
13034
76670
99535
116489
119619
113805
48414
34447
89700
151774
43407
143615
9313
35338
111322
47750
4067
124254
151740
42926
11716
50182
125140
49346
2401
12821
13134
105419
57325
158192
84649
131542
8084
128270
49990
18...

result:

ok 200000 numbers

Test #23:

score: 0
Accepted
time: 680ms
memory: 38304kb

input:

200000 200000
33 56 44 48 76 89 40 28 75 91 15 62 67 23 82 75 91 40 23 46 46 75 15 4 17 46 33 56 93 76 60 78 40 16 8 60 38 36 78 5 37 76 7 48 15 56 26 39 33 66 15 79 51 4 55 70 78 44 36 42 60 33 39 26 97 16 25 42 87 28 91 64 26 64 33 46 17 39 50 7 31 52 78 4 62 39 4 40 44 66 15 50 5 80 79 78 62 91 1...

output:

53224
130791
75981
100822
49641
37228
166672
27098
159752
42324
48854
34705
126895
87470
149583
18499
8254
65398
85901
4527
50583
131675
368
18218
28491
13924
98834
170287
50771
18597
92298
27982
42319
117110
21018
90730
83058
117727
97308
44859
85156
65401
42325
26962
47987
180712
159852
4396
13042...

result:

ok 200000 numbers

Test #24:

score: 0
Accepted
time: 1251ms
memory: 46112kb

input:

200000 200000
706 910 994 778 213 745 302 246 437 58 327 820 910 814 713 159 264 631 567 14 378 473 444 60 166 468 755 391 924 969 613 357 936 259 300 648 653 753 191 116 232 900 722 689 888 283 527 750 494 715 657 238 295 62 786 4 507 409 531 633 732 538 852 968 498 665 862 340 684 349 665 637 112 ...

output:

104365
48496
84558
15825
30943
69925
36578
132326
9096
4501
25778
15277
91242
133511
104800
124458
24302
68990
28153
15653
105093
13220
98478
27147
72578
92616
3026
72605
64959
1904
29997
46904
73803
98854
104360
62119
151484
4832
116386
57525
1744
3252
3499
15444
5893
1583
24316
84035
69537
13280
1...

result:

ok 200000 numbers

Test #25:

score: 0
Accepted
time: 809ms
memory: 41344kb

input:

200000 200000
295068767 621020782 7544515 828416618 992192279 711896173 708068186 532562723 223537817 354287997 992192279 197363103 711896173 130482022 759310232 998024297 794511688 171146436 711896173 105817173 915731636 371731080 439394728 648534644 476450904 807441858 512619715 408180036 35428799...

output:

24267
20230
21853
98986
93587
9662
19138
22229
40906
24483
63928
58568
72511
12554
96834
25994
74191
69906
155211
5852
133879
139650
62103
78933
143808
36299
170542
154874
3090
123239
25196
8676
10598
158764
35771
178657
117989
81377
23499
33207
12579
32683
37442
154672
1977
75862
48381
3682
8646
53...

result:

ok 200000 numbers

Test #26:

score: 0
Accepted
time: 1255ms
memory: 38984kb

input:

200000 200000
790866404 43253838 56308578 715002932 710872334 657805539 393144082 835676255 410166936 891650874 705987765 808162489 64425638 474472168 711748 699534756 253734427 120031047 459003332 270536390 128839555 534941078 806374536 581947805 964012784 201878633 526412138 555349873 310226561 13...

output:

23017
7187
1439
88315
99415
26717
28130
3415
18450
52880
45752
53238
146999
109235
18265
21644
16741
94473
59074
117462
120262
68525
49314
20396
76865
84783
20937
8782
105148
28846
28
32837
98800
37308
82550
5561
69177
169551
81411
64485
84050
53032
21095
36622
29452
40388
49809
27563
21734
118099
3...

result:

ok 200000 numbers

Test #27:

score: 0
Accepted
time: 1467ms
memory: 46200kb

input:

200000 200000
863288351 410445298 303393133 404231659 735462542 276306379 612901588 642373617 355181892 432073589 708732745 392807797 845959190 872685271 823668460 64763859 758320121 312529179 83452817 756143144 68988603 271554999 617710281 142648591 377478042 593055837 181791755 956535190 154295007...

output:

29103
131469
0
39018
108845
88410
88725
24196
136735
49392
32439
126100
109014
45484
18317
118339
11887
1490
12767
85568
18293
0
99030
30662
85568
73588
2955
1984
2741
99030
72337
46757
99030
52512
49392
88725
16336
5723
14822
73324
99030
52512
131469
46757
881
75
69116
139432
106027
17925
0
7553
99...

result:

ok 200000 numbers

Test #28:

score: 0
Accepted
time: 689ms
memory: 33760kb

input:

200000 200000
36567494 36567494 809428300 809428300 809428300 36567494 809428300 36567494 809428300 809428300 36567494 809428300 36567494 809428300 809428300 36567494 36567494 36567494 36567494 36567494 809428300 36567494 809428300 36567494 36567494 36567494 36567494 36567494 809428300 36567494 3656...

output:

118832
23158
91229
18388
125814
13759
25487
68061
186403
99321
157678
80203
31865
84959
30733
94190
22964
44057
83818
51417
15214
108852
88808
87822
51780
180257
163213
83365
158506
32555
184798
123584
13342
89919
48101
94516
149452
18071
80058
2747
54059
36605
19533
144108
67956
118785
54374
76684
...

result:

ok 200000 numbers

Test #29:

score: 0
Accepted
time: 684ms
memory: 37696kb

input:

200000 200000
870692556 835057778 107983550 870692556 870692556 835057778 107983550 835057778 870692556 107983550 107983550 835057778 870692556 107983550 107983550 835057778 107983550 107983550 870692556 870692556 835057778 107983550 107983550 835057778 870692556 107983550 107983550 107983550 835057...

output:

6371
29080
130768
112055
43674
49949
47499
93782
28396
71485
36539
14432
46935
8652
46043
63682
9571
30358
3249
23164
52279
157561
124817
32604
65913
153371
170956
65276
105741
10854
50062
67405
32486
78338
71002
60300
10702
31069
23483
49423
62617
38347
4080
152618
11657
29194
97725
22370
20122
136...

result:

ok 200000 numbers

Test #30:

score: 0
Accepted
time: 730ms
memory: 41980kb

input:

200000 200000
185793956 185793956 185793956 591349437 817875397 342165296 185793956 185793956 342165296 342165296 185793956 389199575 342165296 817875397 389199575 389199575 185793956 389199575 389199575 591349437 342165296 389199575 342165296 591349437 342165296 817875397 342165296 591349437 389199...

output:

46913
89529
24134
170573
114446
68938
7997
31103
72969
59633
79735
56835
50049
41114
47207
140404
17319
43757
101139
4229
58572
32486
953
74539
15953
138366
26574
97580
84707
22077
3147
15208
91183
35358
71721
11880
21655
96330
26053
102470
43518
129721
101327
28916
41531
16574
134299
20105
137017
1...

result:

ok 200000 numbers

Test #31:

score: 0
Accepted
time: 739ms
memory: 34172kb

input:

200000 200000
552616145 454731244 256773570 261840848 748293716 648633300 648633300 508263494 351258801 57339490 774977574 10911418 720264596 691623751 784287626 865146652 508263494 593508966 57339490 454731244 668867315 748293716 718995713 56181971 865146652 256773570 555969926 546317073 554064104 ...

output:

38877
37460
60774
3301
85929
29231
3069
46644
43111
73144
73346
59764
164242
21262
32655
54332
144996
102752
29918
97898
94390
10332
25848
88101
8309
27950
1576
68267
74065
32264
58774
101292
21736
34784
53005
32358
55793
120744
48711
31599
122537
122695
117557
127026
33219
33127
70101
28797
104475
...

result:

ok 200000 numbers

Test #32:

score: 0
Accepted
time: 1335ms
memory: 44396kb

input:

200000 200000
265701919 215867294 860705814 362129260 298140543 900813915 951125496 926522835 708342656 401009014 7095309 360317755 201255894 276437642 153926115 570791492 233651469 865962062 864451332 615304704 699268259 803405964 450393013 195149555 154270325 854332762 937339739 363122842 59394132...

output:

4301
4119
0
1
0
4301
4301
4301
4301
0
0
4301
4301
757
4301
0
4301
7055
3
7055
4301
2
4301
4119
1
4119
4301
2
4301
4301
4119
0
7055
0
4301
0
4301
4301
0
4301
7055
4301
0
7055
7055
4301
7055
4301
4301
0
4119
4301
4119
4301
4119
0
4119
1
7055
4301
7055
7055
4301
4301
4119
4301
4301
7055
4301
4301
152
7...

result:

ok 200000 numbers

Test #33:

score: 0
Accepted
time: 1187ms
memory: 43068kb

input:

200000 200000
371783560 579560953 585381148 997764441 413440324 492512424 49913231 464932318 3414115 819645259 245620623 850698829 170251611 562268605 581986337 589232012 514012408 402502939 87018943 378063213 252122809 555505061 469802172 222904681 129181122 567066458 120890921 401329807 488846130 ...

output:

0
1043
13
1043
1043
1043
57748
1043
57748
0
1043
0
57748
0
0
0
1043
57748
1043
57748
13
0
0
1043
25
1043
0
0
0
0
1043
0
1043
57748
0
0
57748
0
0
0
0
25
1043
1043
0
0
0
0
1043
0
1043
0
1043
25
13
0
1043
1043
0
1043
25
0
25
0
57748
1043
1043
25
0
0
0
0
0
0
1043
0
0
0
0
0
1043
25
0
0
0
1043
57748
57748...

result:

ok 200000 numbers

Test #34:

score: 0
Accepted
time: 2814ms
memory: 68372kb

input:

500000 500000
6 7 7 7 1 6 6 1 1 6 7 6 6 1 1 6 7 6 7 1 7 1 6 1 1 6 1 1 6 1 7 6 7 7 7 7 7 6 6 7 6 1 1 6 6 1 7 1 6 1 1 6 7 7 7 1 6 6 7 7 7 7 7 7 7 7 7 7 7 6 6 1 6 7 1 6 1 1 6 6 7 7 7 1 7 6 7 7 6 1 6 1 7 1 7 1 1 6 6 7 7 7 7 7 7 6 1 6 6 6 1 6 7 1 7 1 6 7 1 7 1 7 1 6 1 6 7 1 6 7 6 7 6 1 7 1 1 7 6 1 1 6 7 ...

output:

63582
279439
194913
37697
5585
435495
237323
244582
134408
234961
346240
306270
379780
241786
206710
215305
341253
425041
171239
200496
230263
306111
195019
398902
66314
151431
6504
78082
46367
103085
36290
58806
64922
332300
211089
66312
121223
166627
444235
344415
305517
356128
11093
186205
260516...

result:

ok 500000 numbers

Test #35:

score: 0
Accepted
time: 2753ms
memory: 68304kb

input:

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

output:

35681
146632
9224
107963
273454
58772
381251
51246
102678
231059
67800
9612
46612
241680
44526
7431
66301
333350
430830
41413
250661
179878
35913
46399
311212
384804
188291
130636
337950
67071
201355
336817
265152
356761
478829
76824
256031
302940
240761
66758
253384
248481
37322
96737
144211
54464
...

result:

ok 500000 numbers

Test #36:

score: 0
Accepted
time: 2915ms
memory: 68764kb

input:

500000 500000
28 14 96 11 41 56 28 28 53 89 30 91 16 72 63 71 89 28 22 78 10 9 95 72 56 84 87 54 30 3 9 23 23 22 96 95 53 23 20 22 96 56 72 14 13 28 31 54 97 11 10 88 84 12 49 56 8 1 5 3 51 8 51 91 62 59 54 30 36 97 90 13 79 96 4 11 9 14 62 7 14 11 82 31 53 88 36 62 5 7 59 55 78 41 32 30 56 84 54 99...

output:

4896
151701
94978
106401
232045
111095
175556
206167
142086
18515
41669
54170
293284
125121
23516
77260
290970
326383
141210
255276
26050
247864
50254
328191
209484
112161
73830
32853
112237
125629
15820
26066
121484
32765
42704
271880
143037
50437
193877
333755
40478
221583
1826
133767
326876
10869...

result:

ok 500000 numbers

Test #37:

score: -100
Time Limit Exceeded

input:

500000 500000
924 550 874 371 795 967 266 697 555 199 42 160 94 811 751 579 617 365 614 269 645 383 789 920 870 257 422 233 853 330 253 781 683 470 165 16 327 430 169 875 543 88 397 867 374 748 85 19 995 878 100 891 563 185 494 946 912 74 865 469 588 870 963 628 967 715 643 915 659 699 14 730 261 44...

output:


result: