QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152391#6846. Wiring Engineering275307894aAC ✓3787ms46860kbC++144.4kb2023-08-28 06:47:212023-08-28 06:47:22

Judging History

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

  • [2023-08-28 06:47:22]
  • 评测
  • 测评结果:AC
  • 用时:3787ms
  • 内存:46860kb
  • [2023-08-28 06:47:21]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=500+5,M=3e5+5,K=(1<<15)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,q,A[N],B[N],w[N][N],ans[M];
struct ques{int x,y,l,r,id;};
int g1[N][N][2][2],g2[N][N][2][2];
void chx(int &x,int y){x=max(x,y);}
void Solve(int l,int r,int x,int y,vector<ques> q){
	if(l>r||x>y||q.empty()) return;
	if(r-l+1>=y-x+1){
		int m=l+r>>1;
		vector<ques> q1,q2,q3;
		for(ques i:q){
			if(i.r<m) q1.emplace_back(i);
			else if(i.l>m) q2.emplace_back(i);
			else q3.emplace_back(i);
		}
		Solve(l,m-1,x,y,q1);Solve(m+1,r,x,y,q2);
		for(int i=x;i<=y;i++){
			for(int o1=0;o1<2;o1++){
				for(int j=l;j<=m;j++) for(int h=x;h<=i;h++) Me(g1[j][h],-0x3f);
				g1[m][i][o1][1]=-A[m]*o1-B[i];
				for(int j=m;j>=l;j--)for(int h=i;h>=x;h--){
					for(int o3=0;o3<2;o3++) for(int o4=0;o4<2;o4++){
						if(o3&&o4) g1[j][h][1][1]+=w[j][h];
						if(!o3&&j^m) chx(g1[j][h][1][o4],g1[j][h][0][o4]-A[j]);
						if(!o4&&h^i) chx(g1[j][h][o3][1],g1[j][h][o3][0]-B[h]);
						if(j>l) chx(g1[j-1][h][0][o4],g1[j][h][o3][o4]);
						if(h>x) chx(g1[j][h-1][o3][0],g1[j][h][o3][o4]);
					}
				}
				for(int j=m;j<=r;j++) for(int h=i;h<=y;h++) Me(g2[j][h],-0x3f);
				g2[m][i][o1][1]=-A[m]*o1-B[i];
				for(int j=m;j<=r;j++) for(int h=i;h<=y;h++){
					for(int o3=0;o3<2;o3++) for(int o4=0;o4<2;o4++){
						if(o3&&o4) g2[j][h][1][1]+=w[j][h];
						if(!o3&&j^m) chx(g2[j][h][1][o4],g2[j][h][0][o4]-A[j]);
						if(!o4&&h^i) chx(g2[j][h][o3][1],g2[j][h][o3][0]-B[h]);
						if(j<r) chx(g2[j+1][h][0][o4],g2[j][h][o3][o4]);
						if(h<y) chx(g2[j][h+1][o3][0],g2[j][h][o3][o4]);
					}
				}
				for(ques j:q3) if(j.x<=i&&j.y>=i) {
					int m1=-INF,m2=-INF;
					for(int p1=0;p1<2;p1++) for(int p2=0;p2<2;p2++) m1=max(m1,g1[j.l][j.x][p1][p2]);
					for(int p1=0;p1<2;p1++) for(int p2=0;p2<2;p2++) m2=max(m2,g2[j.r][j.y][p1][p2]);
					ans[j.id]=max(ans[j.id],m1+m2+o1*A[m]+B[i]-o1*w[m][i]);
				}
			}
		}
	}else{
		int m=x+y>>1;
		vector<ques> q1,q2,q3;
		for(ques i:q){
			if(i.y<m) q1.emplace_back(i);
			else if(i.x>m) q2.emplace_back(i);
			else q3.emplace_back(i);
		}
		Solve(l,r,x,m-1,q1);Solve(l,r,m+1,y,q2);
		for(int i=l;i<=r;i++){
			for(int o2=0;o2<2;o2++){
				for(int j=l;j<=i;j++) for(int h=x;h<=m;h++) Me(g1[j][h],-0x3f);
				g1[i][m][1][o2]=-A[i]-B[m]*o2;
				for(int j=i;j>=l;j--)for(int h=m;h>=x;h--){
					for(int o3=0;o3<2;o3++) for(int o4=0;o4<2;o4++){
						if(o3&&o4) g1[j][h][1][1]+=w[j][h];
						if(!o3&&j^i) chx(g1[j][h][1][o4],g1[j][h][0][o4]-A[j]);
						if(!o4&&h^m) chx(g1[j][h][o3][1],g1[j][h][o3][0]-B[h]);
						if(j>l) chx(g1[j-1][h][0][o4],g1[j][h][o3][o4]);
						if(h>x) chx(g1[j][h-1][o3][0],g1[j][h][o3][o4]);
					}
				}
				for(int j=i;j<=r;j++) for(int h=m;h<=y;h++) Me(g2[j][h],-0x3f);
				g2[i][m][1][o2]=-A[i]-B[m]*o2;
				for(int j=i;j<=r;j++) for(int h=m;h<=y;h++){
					for(int o3=0;o3<2;o3++) for(int o4=0;o4<2;o4++){
						if(o3&&o4) g2[j][h][1][1]+=w[j][h];
						if(!o3&&j^i) chx(g2[j][h][1][o4],g2[j][h][0][o4]-A[j]);
						if(!o4&&h^m) chx(g2[j][h][o3][1],g2[j][h][o3][0]-B[h]);
						if(j<r) chx(g2[j+1][h][0][o4],g2[j][h][o3][o4]);
						if(h<y) chx(g2[j][h+1][o3][0],g2[j][h][o3][o4]);
					}
				}
				for(ques j:q3) if(j.l<=i&&j.r>=i) {
					int m1=-INF,m2=-INF;
					for(int p1=0;p1<2;p1++) for(int p2=0;p2<2;p2++) m1=max(m1,g1[j.l][j.x][p1][p2]);
					for(int p1=0;p1<2;p1++) for(int p2=0;p2<2;p2++) m2=max(m2,g2[j.r][j.y][p1][p2]);
					ans[j.id]=max(ans[j.id],m1+m2+A[i]+o2*B[m]-o2*w[i][m]);
				}
			}
		}
	}
}
void Solve(){
	int i,j;scanf("%d%d",&n,&q);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	for(i=1;i<=n;i++) scanf("%d",&B[i]);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++) scanf("%d",&w[i][j]);
	}
	vector<ques> Q;
	for(i=1;i<=q;i++){
		ques p;scanf("%d%d%d%d",&p.l,&p.r,&p.x,&p.y);p.id=i;
		Q.emplace_back(p);
	}
	Solve(1,n,1,n,Q);
	for(i=1;i<=q;i++) printf("%d\n",ans[i]);
}
int main(){
	int t;
	// scanf("%d",&t);
	t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 5984kb

input:

3 4
1 2 1
2 1 2
1 2 3
4 5 6
3 2 1
1 3 1 3
2 3 1 2
1 1 2 3
1 2 2 3

output:

8
5
1
7

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 13ms
memory: 14968kb

input:

24 90000
8793 8115 9643 2814 6394 7070 3822 4788 6737 6506 2901 4772 5347 5050 3493 2803 584 2544 3834 678 9891 2958 5475 522
9057 3674 3163 6433 5937 8480 4815 1201 5509 1303 4151 8190 6229 9339 9765 3011 2256 3682 8442 3641 2268 5609 4948 9632
5872 4006 7690 2611 5381 6184 9483 8527 8248 960 8124 ...

output:

0
0
0
0
0
0
734
8060
10799
10799
14772
14772
14772
14772
14772
20708
24243
25895
27159
33403
33403
33403
33469
33469
0
0
0
0
0
734
8060
10799
10799
14772
14772
14772
14772
14772
20708
24243
25895
27159
33403
33403
33403
33469
33469
0
0
0
0
402
7728
10467
10467
14440
14440
14440
14440
14440
20376
239...

result:

ok 90000 lines

Test #3:

score: 0
Accepted
time: 22ms
memory: 12904kb

input:

24 90000
2882 8334 4022 5376 8457 3340 867 899 1508 727 7364 623 6553 7553 7719 6763 7732 3004 5920 4146 6661 4104 6283 8972
4478 5974 4930 4992 3905 9280 5603 2194 7539 6619 5862 151 8423 5365 219 5041 7657 7324 5990 3400 8540 4062 4172 7347
8383 9811 9948 8647 930 20 3735 8411 4325 4279 8849 3616 ...

output:

1023
4860
9878
13533
13533
13533
13533
19750
19750
19750
22737
26202
26202
26202
30484
31526
31526
32471
32471
38273
38273
43569
48112
48112
955
5973
9628
9628
9628
9628
15845
15845
15845
18832
22297
22297
22297
26579
27621
27621
28566
28566
34368
34368
39664
44207
44207
2136
5791
5791
5791
5791
120...

result:

ok 90000 lines

Test #4:

score: 0
Accepted
time: 29ms
memory: 13300kb

input:

24 90000
5827 3068 5413 8083 80 9169 8321 3897 4658 7830 2340 8206 1214 6308 5129 1455 2916 1859 2482 5258 7060 9652 1082 800
8155 1732 6246 3960 245 1183 1414 1277 4968 8201 6267 1932 1361 6774 1087 2440 3409 5345 8071 3990 632 7664 4733 5294
1185 6622 9262 7354 2910 1548 9877 2515 9039 9202 2820 2...

output:

0
0
2079
5473
8138
8503
16966
18204
22275
23276
23276
24228
24464
25082
28124
34856
34856
36225
36225
36225
36225
36225
36225
40176
0
2079
5473
8138
8503
16966
18204
22275
23276
23276
24228
24464
25082
28124
34856
34856
36225
36225
36225
36225
36225
36225
40176
0
583
3248
3613
12076
13314
17385
1838...

result:

ok 90000 lines

Test #5:

score: 0
Accepted
time: 28ms
memory: 14356kb

input:

24 90000
228 448 373 1000 1000 49 571 217 799 531 838 609 889 615 683 578 956 218 842 100 180 312 835 691
803 486 792 277 841 190 476 794 717 234 109 947 795 631 353 1000 708 501 113 708 125 716 452 915
9676 6488 8908 3177 3346 767 6103 2588 9360 3035 1212 564 8822 4147 8260 8212 6538 6006 8716 5567...

output:

8645
14647
22763
25663
28168
28745
34372
36166
44809
47610
48713
48713
56740
60256
68163
75375
81205
86710
95313
100172
107154
115433
124423
126873
5774
13890
16790
19295
19872
25499
27293
35936
38737
39840
39840
47867
51383
59290
66502
72332
77837
86440
91299
98281
106560
115550
118000
7888
10788
1...

result:

ok 90000 lines

Test #6:

score: 0
Accepted
time: 33ms
memory: 13236kb

input:

24 90000
57 21 22 28 66 90 53 16 85 37 59 21 34 17 16 47 21 32 22 27 93 52 63 66
15 7 77 52 38 42 24 38 81 49 57 45 36 63 23 93 75 28 23 34 48 71 78 64
8367 4296 343 546 7650 5845 8498 5888 2483 9099 2698 5872 3982 1036 6415 4326 9263 7076 7818 7907 6825 3203 2048 5487
6642 3448 1683 9585 9322 1651 ...

output:

8295
12584
12850
13344
20956
26759
35233
41083
43485
52535
55176
61003
64949
65922
72314
76547
85735
92783
100578
108451
115228
118360
120330
125753
4232
4498
4992
12604
18407
26881
32731
35133
44183
46824
52651
56597
57570
63962
68195
77383
84431
92226
100099
106876
110008
111978
117401
209
703
831...

result:

ok 90000 lines

Test #7:

score: 0
Accepted
time: 18ms
memory: 14460kb

input:

24 90000
2 2 10 6 7 7 2 9 1 8 1 2 9 6 6 10 7 8 7 6 6 5 4 5
3 9 4 5 2 3 8 2 6 2 6 2 5 1 10 5 4 3 2 6 5 7 1 1
8155 8001 2384 8872 2623 129 2105 9830 6007 6485 9339 7456 6246 1156 2019 1875 8275 6950 7885 4501 114 1456 9206 5279
9157 6539 6206 9430 353 5870 4767 6957 6129 3742 9953 8631 9898 8230 9641 ...

output:

8150
16142
18522
27389
30010
30136
32233
42061
48062
54545
63878
71332
77573
78728
80737
82607
90878
97825
105708
110203
110312
111761
120966
126244
7990
10370
19237
21858
21984
24081
33909
39910
46393
55726
63180
69421
70576
72585
74455
82726
89673
97556
102051
102160
103609
112814
118092
2378
1124...

result:

ok 90000 lines

Test #8:

score: 0
Accepted
time: 21ms
memory: 12736kb

input:

24 90000
1571 8593 7110 9439 5693 6004 2083 6762 6156 1082 3311 4826 2735 1518 4964 1627 8600 5434 1698 2333 1492 1819 9208 2385
6759 1678 1244 3701 7214 7740 7859 2612 1754 3579 702 7842 7407 6886 5612 9788 3791 803 8242 9388 2543 588 2137 3026
14 563 354 730 30 468 695 422 800 230 867 880 753 350 ...

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 90000 lines

Test #9:

score: 0
Accepted
time: 31ms
memory: 12640kb

input:

24 90000
9515 4114 9111 3785 1401 5622 2365 4538 8244 4565 1230 4659 6600 3020 4874 9402 7318 2149 8497 8821 657 3842 5678 9041
9219 834 1567 7528 7313 4701 6148 825 1732 3368 6419 6495 891 3569 9742 3361 5403 8315 5596 1155 6579 3964 772 4468
92 61 97 17 83 25 29 92 14 37 15 32 50 54 9 41 59 14 100...

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 90000 lines

Test #10:

score: 0
Accepted
time: 25ms
memory: 14356kb

input:

24 90000
7875 1831 8812 3686 3105 6713 7181 2621 3079 6665 4084 8202 6751 7113 1494 1987 9855 2854 12 5890 9938 529 9565 9636
5255 6704 8421 6138 595 5015 838 4001 5426 5839 3906 5656 568 6666 1024 8857 8690 237 8891 6247 6726 3097 1844 6980
9 3 8 1 8 9 3 7 4 7 8 7 1 5 6 3 3 5 3 3 4 3 8 3
9 3 10 8 8...

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 90000 lines

Test #11:

score: 0
Accepted
time: 759ms
memory: 19232kb

input:

300 100000
5892 2941 7796 3824 7699 6234 1720 4553 2224 3340 9567 897 7270 8556 8074 3842 7509 6342 9185 3140 3418 9783 8997 2773 8953 3806 9039 5780 5753 2259 6707 3211 3341 9795 8101 486 449 2952 3278 5997 1371 7167 5793 6654 4562 8639 8974 3875 754 7239 5575 4763 7555 4170 306 613 61 5074 2372 45...

output:

1364797
946433
634894
474007
768328
443123
542090
200215
287951
296984
190606
1146449
709971
919511
543428
787464
863764
980126
145438
413745
583043
1151004
138271
741758
344448
396168
282972
559104
625322
1017928
329022
1020933
441078
554377
886603
651482
791217
538517
181464
562969
662860
311649
4...

result:

ok 100000 lines

Test #12:

score: 0
Accepted
time: 757ms
memory: 18832kb

input:

300 100000
6268 1156 2360 305 185 7948 884 3679 9996 3778 3727 7152 7329 2502 5778 3837 4353 198 4953 253 656 2762 2736 3861 5243 6592 3070 7190 9210 8017 174 6078 833 5170 5193 1132 7791 1613 8691 5650 2807 7694 7688 6304 7548 3315 2253 4529 5277 9817 1356 6463 2885 6682 3681 1261 6508 63 1024 4707...

output:

594192
664164
709764
911359
830339
1465776
847623
445582
1012558
472484
1023314
733688
370710
457441
682893
746625
1003832
98769
979488
439442
72686
370339
269618
1383271
377547
701678
62656
645637
865577
598519
685255
503807
382531
143509
841485
371148
454701
185208
346999
715422
892361
793054
4645...

result:

ok 100000 lines

Test #13:

score: 0
Accepted
time: 758ms
memory: 18904kb

input:

300 100000
3427 2804 298 9132 705 7279 4384 6949 3693 7286 8284 9913 7929 7021 9878 2202 2883 2121 7131 8468 6085 722 2490 7970 4702 6264 8136 6544 478 9413 2470 518 190 9524 8652 4940 8764 7252 3326 6090 6874 2387 4206 3324 5978 8513 2849 230 8044 3717 2312 1040 1917 9631 9986 9055 858 4846 9249 40...

output:

459933
876199
349360
728416
377659
1418424
1055339
229755
207568
525787
560076
687940
605657
402795
379959
103061
783783
550977
185993
1378825
715382
442275
609454
784052
694823
209646
927888
495233
682011
159373
221676
235598
586269
781145
701797
280268
503466
476109
326949
160359
244893
841634
101...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 761ms
memory: 20496kb

input:

300 100000
203 112 810 54 965 763 752 945 162 116 481 596 572 338 771 378 525 758 317 832 167 96 416 324 155 830 940 390 943 604 954 996 112 226 143 583 678 681 254 704 794 405 869 932 968 244 73 78 165 470 795 416 232 111 847 82 919 234 903 370 433 513 740 550 738 249 415 492 283 857 281 770 813 42...

output:

995321
153484
1788754
1072283
1029180
485125
617623
2787299
2406603
1083441
600958
1042863
1017166
711052
1597637
1101400
1480995
1591242
1136224
1770419
1321613
1019176
1907413
737598
2016230
410406
1434243
85954
1406674
762096
604562
448091
585744
1600657
429106
636858
748323
2800424
744925
270864...

result:

ok 100000 lines

Test #15:

score: 0
Accepted
time: 767ms
memory: 18128kb

input:

300 100000
10 62 93 8 64 37 6 27 25 11 85 81 78 3 24 15 40 40 51 90 50 5 14 27 6 44 60 20 42 85 88 43 97 14 100 19 91 33 32 54 21 18 4 98 3 35 94 98 32 81 30 12 88 87 53 54 85 82 76 67 81 54 21 1 45 28 82 99 16 27 32 5 94 96 63 7 51 80 4 39 38 50 46 95 4 61 99 54 76 99 47 65 28 87 88 7 42 46 72 28 9...

output:

727938
1465680
394429
2087611
3403699
1148390
1252684
684796
1477054
856947
2972151
1478885
449508
1930961
649064
602516
1046342
254644
588557
1383781
261661
237514
1053488
756980
613517
1508726
1165965
185712
2855687
580217
2054256
1211662
938828
1523668
650548
631591
1353228
1360711
928520
944771
...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 757ms
memory: 20612kb

input:

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

output:

1014930
1346371
1589962
494375
1563207
1218325
804173
735284
1785496
327773
1633611
1281824
1870426
815071
580509
1276090
284276
2255907
598916
2092307
953528
1551905
2277598
848017
1654284
381809
1451204
3101713
113919
354538
2074374
1264404
1167540
760069
1557682
1719804
1318711
549026
1147358
878...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 761ms
memory: 20664kb

input:

300 100000
3929 9383 3139 5566 8662 3751 7348 2114 5423 5267 4176 8566 5586 3532 4356 9147 6577 2066 9348 8019 6308 1508 4061 1334 627 6320 2446 5418 777 9879 3403 2241 1558 7262 6621 9617 4897 494 8647 5663 1717 9610 7065 9341 9029 4770 7296 374 6674 7419 772 3953 7570 2890 554 312 5379 2623 4243 3...

output:

1600
9470
639
3820
7084
5042
152
6684
3400
4904
438
9676
7983
4077
8412
7076
7725
6622
2291
5490
5979
3898
14341
6513
498
8987
3767
7765
3680
5888
2261
7047
5520
3138
6504
1462
2624
3995
3341
11918
9218
6776
454
0
0
2778
608
7364
778
2138
4412
14518
2219
3182
10627
4023
4781
878
9885
3052
1370
1044
...

result:

ok 100000 lines

Test #18:

score: 0
Accepted
time: 769ms
memory: 18224kb

input:

300 100000
3112 8934 421 7792 3527 4028 5471 1329 9133 7175 2260 2604 6673 1445 3068 2895 5285 5003 9970 1846 765 8180 1616 1939 2502 6430 2351 3904 5111 6225 228 103 6178 2566 1048 4229 4126 4668 4042 5118 9620 6697 640 4142 2729 1103 9446 4459 4363 6088 2809 8210 119 9613 1950 9540 1348 9516 8003 ...

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 100000 lines

Test #19:

score: 0
Accepted
time: 755ms
memory: 20648kb

input:

300 100000
5803 7547 6909 4457 8699 6825 8469 885 1728 5483 565 7815 3322 4322 7653 4866 6142 9753 4423 8057 9119 9290 9681 281 3659 6296 9307 8761 9587 5406 9160 6508 2647 4843 3652 2365 1418 3639 4700 187 168 8298 1510 3876 6582 8246 515 7054 9401 9765 5793 4986 3810 9022 9469 7731 955 5392 3658 7...

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 100000 lines

Test #20:

score: 0
Accepted
time: 3787ms
memory: 38936kb

input:

500 300000
8897 103 1496 3525 3524 2591 3767 3998 1607 4835 7462 8224 4406 1683 5324 2067 4867 3711 9666 7955 9393 4540 6056 4543 6393 6678 9712 4811 248 7112 5169 494 735 7589 8565 1029 2338 5651 6043 9806 1754 8379 8278 9678 5171 7371 6811 4108 9582 7140 6727 8771 2416 2267 1112 5684 1090 76 4479 ...

output:

336007
1908436
1133643
1094904
1935118
1746210
2316682
983207
1121973
2115464
1803171
1557392
133583
1397317
1249410
2010496
434101
219039
430763
667254
976388
1337279
339073
510827
979050
207478
1621132
957744
871500
252393
1304464
1982167
1008271
1488878
1924914
1912742
1120633
370614
1526644
4425...

result:

ok 300000 lines

Test #21:

score: 0
Accepted
time: 3715ms
memory: 41132kb

input:

500 300000
393 999 729 914 245 62 176 867 539 429 996 527 427 603 498 62 564 467 600 573 518 993 9 787 438 489 876 438 917 992 693 476 18 24 611 842 827 777 496 113 944 786 837 795 233 764 723 994 386 488 946 306 958 155 110 194 81 929 493 608 781 952 594 154 478 256 325 413 710 626 553 9 610 782 60...

output:

2111883
2347161
3484287
2909933
4361331
2401458
1200065
1205990
1070818
3887907
1293406
2223595
207292
2242770
2387631
788662
3911813
2884196
1149135
3260559
1934415
1020928
2919657
781517
617536
1355970
1254414
3876378
1855443
1427447
4433323
861214
2611875
1609770
2613638
2346891
1440134
1292947
3...

result:

ok 300000 lines

Test #22:

score: 0
Accepted
time: 3735ms
memory: 40412kb

input:

500 300000
13 13 58 12 43 45 40 61 39 14 1 84 36 4 86 56 29 91 69 7 35 81 12 25 36 34 28 95 65 62 3 96 41 46 70 52 68 76 84 12 41 42 13 24 20 3 11 81 45 59 57 79 12 49 10 91 47 52 51 42 50 39 71 53 42 96 28 59 10 50 25 51 64 2 18 22 74 10 85 77 67 82 21 9 38 85 62 69 15 86 98 33 29 92 87 89 8 44 63 ...

output:

2418323
1389133
4349485
1007810
1483977
1620113
763293
2681374
4143788
270943
2720821
1036582
3368180
2140104
1021167
4339150
5020589
1195060
2268076
2018726
1631891
1387833
1510722
2504717
1754028
1372046
1379819
3888372
3485980
1269823
5530456
3856258
921440
1963971
1356877
3144873
1849650
5417302...

result:

ok 300000 lines

Test #23:

score: 0
Accepted
time: 3700ms
memory: 40492kb

input:

500 300000
8 9 4 2 1 10 5 6 4 1 9 8 9 2 5 10 4 10 4 1 9 6 5 8 9 8 2 9 4 7 9 5 1 9 5 2 6 5 9 2 4 9 4 9 8 3 9 10 6 1 9 2 7 3 2 10 9 4 8 4 5 3 2 3 2 7 7 7 9 6 7 4 8 4 6 5 2 5 10 5 5 3 6 4 1 3 8 4 2 7 1 7 3 10 3 6 10 4 8 2 10 6 6 3 8 4 10 3 10 4 3 9 9 8 5 2 9 7 8 7 4 1 8 2 2 5 6 3 8 3 8 5 4 8 7 5 8 2 4 ...

output:

1707397
2644183
4624817
3152941
2478069
2199565
5277310
1701966
445503
3665442
1902903
3727448
1885034
3823895
2505213
2211199
2376510
2452870
1702694
1991579
3113005
4066500
3314171
605794
3089457
1078338
2940696
1752047
1424356
544817
2311759
3471727
135142
1656901
4454228
394974
1700005
3282212
1...

result:

ok 300000 lines

Test #24:

score: 0
Accepted
time: 3731ms
memory: 41060kb

input:

500 300000
9722 4702 3630 4924 1294 53 735 1693 9567 271 7085 305 9151 5126 7294 258 1333 84 1098 7455 9516 89 239 2393 8308 8555 5918 7415 2240 5217 4699 8690 967 4680 2448 1178 5540 6015 9258 1215 1430 7146 1803 1816 2480 7938 839 2544 9402 5026 3383 7812 6542 5084 1049 8934 9548 5203 9181 2733 66...

output:

3142
5374
5730
10561
3665
1792
1547
3492
8318
3654
4010
719
10514
1788
6555
7350
15339
7365
8242
6964
4423
4010
1277
1503
1912
15312
8404
7156
796
13055
6180
6594
6050
11991
9363
1037
1384
10379
17550
9328
6493
4695
7425
13630
8598
11441
2157
3843
4378
7859
10628
6860
1187
254
4916
1782
23847
11939
...

result:

ok 300000 lines

Test #25:

score: 0
Accepted
time: 3739ms
memory: 39512kb

input:

500 300000
1808 8700 3638 1409 2235 5589 2208 3030 4188 4137 5662 6446 7541 677 8703 5696 1823 6586 6435 8071 1813 251 4033 7120 4759 6467 9346 7023 2920 1981 5140 2842 2961 1562 7815 860 4956 8191 3491 9540 4329 4196 8289 339 7612 8710 4909 1938 5053 9061 3115 1273 7559 2519 2991 6601 3833 2835 981...

output:

0
42
0
0
0
0
0
0
75
0
4
46
90
42
0
62
90
0
0
0
0
0
0
0
69
62
0
0
0
4
4
4
0
0
0
0
90
0
0
21
0
0
0
46
73
0
90
34
0
106
75
90
0
4
0
0
86
42
116
0
0
0
0
0
106
21
0
73
90
0
0
0
42
0
0
116
62
0
34
0
73
90
73
90
0
90
90
67
0
0
0
0
73
4
0
116
73
108
0
67
75
90
73
0
0
90
75
90
21
0
42
0
0
73
0
75
73
90
0
73
...

result:

ok 300000 lines

Test #26:

score: 0
Accepted
time: 3759ms
memory: 40900kb

input:

500 300000
2118 3717 6749 439 4850 3359 2774 2702 1883 7905 2314 3365 8135 13 4850 371 15 3052 5512 4095 8610 6183 9582 1303 8018 5678 8520 524 2821 1269 541 2372 1157 1794 4906 4743 2001 1393 1151 51 5738 8064 7056 5353 9751 7507 2373 157 785 1585 1002 4825 9303 9349 1216 6538 9788 8590 7642 4914 4...

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 300000 lines

Test #27:

score: 0
Accepted
time: 3268ms
memory: 44324kb

input:

500 300000
2321 6243 4753 7194 2778 4072 5750 7986 8467 6314 606 671 7201 5412 5647 9984 2589 1269 3092 707 7333 2318 3565 414 2954 9590 3933 2375 369 6982 4395 6572 3026 1022 674 2925 7068 9918 5984 3021 559 6494 9867 4132 9168 5750 919 8351 7496 5606 5649 5119 8214 4192 4008 5622 2680 6697 1822 81...

output:

1224746
1217406
660019
1815247
1607535
1287117
854895
2215894
855036
1334531
1043227
592651
1715877
2413153
344597
1356104
1140878
658460
1005946
1532967
1947873
1898162
1538822
1125851
764490
264950
1768248
1745827
692839
2201622
1082929
2110609
1385304
618992
2419679
2652363
829100
1943218
2154611...

result:

ok 300000 lines

Test #28:

score: 0
Accepted
time: 3299ms
memory: 46760kb

input:

500 300000
5745 5088 9499 6672 7839 2848 1926 1974 5326 3200 1046 7711 7291 7653 162 4797 7208 5723 1110 4948 1082 5904 1075 4797 6811 2502 8154 1428 4681 6853 3621 6843 8421 7158 9678 3333 1798 7289 3222 3131 8148 7712 8352 5483 61 9538 435 9891 8114 8265 6059 1067 2795 5716 4200 2856 1567 3318 767...

output:

0
0
0
0
0
4677
0
0
2471
0
0
0
0
1632
10694
11158
10568
30843
26014
23101
9841
35048
18187
33765
34509
15573
15573
38758
39895
41142
40569
44381
0
45884
23928
68124
48974
25042
10984
19156
71202
17042
77892
67046
0
28095
28095
96302
90168
95614
19184
85285
30687
77316
93629
46742
0
54465
65699
60418
...

result:

ok 300000 lines

Test #29:

score: 0
Accepted
time: 3312ms
memory: 46860kb

input:

500 300000
817 139 283 688 499 134 455 151 694 611 140 78 326 741 117 683 478 513 322 518 266 771 518 171 295 505 98 299 334 862 920 850 309 457 424 250 261 147 734 223 45 901 426 250 421 848 830 238 4 146 764 654 947 784 302 941 672 550 348 412 484 57 633 431 509 814 110 832 309 952 806 499 329 294...

output:

5883930
3013008
6234566
5015954
991181
2841200
1522927
3550898
4706162
5096572
3095774
3469517
4349258
1050325
2844902
1742443
2845143
1440035
2788202
4765864
1191280
4824096
3751675
3839414
4055325
6167244
1113372
3874359
3553674
1196713
2120542
327181
5188916
4478840
2385936
6102112
305878
4292020...

result:

ok 300000 lines

Test #30:

score: 0
Accepted
time: 3279ms
memory: 44920kb

input:

500 300000
61 9 57 71 55 99 99 41 54 78 92 75 16 78 24 94 74 4 10 1 32 36 39 83 54 54 63 9 94 7 55 45 31 15 84 56 23 26 63 29 39 75 87 32 6 74 34 57 85 84 88 82 82 90 99 64 24 98 65 58 61 66 45 9 96 18 90 6 99 10 18 23 99 18 64 83 91 80 83 1 64 94 82 57 12 17 2 59 14 27 70 58 51 22 2 73 33 47 51 26 ...

output:

6565
1727
9843
8190
16567
14046
9070
28698
34065
50305
49252
56925
34682
73471
47182
15
78746
26095
69076
87712
79492
568
35882
43279
66016
34003
56268
126962
20661
35896
77599
15657
53364
156256
23734
169321
92444
108733
74651
8964
124459
7178
41756
173580
240434
160074
29662
13955
232700
209936
23...

result:

ok 300000 lines

Test #31:

score: 0
Accepted
time: 3273ms
memory: 45284kb

input:

500 300000
6 3 7 3 10 7 2 8 10 4 4 2 9 2 8 7 1 8 10 2 9 8 7 7 10 1 3 2 4 5 5 1 8 1 10 8 1 10 1 2 3 1 9 7 5 10 10 4 4 9 8 7 8 10 8 4 8 5 5 6 6 5 7 1 7 1 6 9 8 10 10 10 3 10 5 8 8 2 3 6 7 5 2 8 6 9 2 1 2 10 1 7 5 1 4 6 8 7 10 8 9 4 7 8 10 6 8 2 4 5 2 4 2 7 3 3 1 5 6 1 9 5 2 2 9 7 4 4 2 5 1 1 4 1 5 6 3...

output:

1890804
3315718
2384704
4626271
5909069
1861164
3985642
1089140
6845826
2987780
5403748
2824678
3813303
2295023
2004359
3925553
3250606
4924027
3005191
3401027
3262488
5159076
4173811
5151817
641439
2241389
727156
1842795
751528
2376333
2327005
601574
5273204
3026439
2990651
1206187
2233340
1269038
...

result:

ok 300000 lines

Test #32:

score: 0
Accepted
time: 3281ms
memory: 43664kb

input:

500 300000
6570 2391 1633 6583 5609 7607 1598 2373 582 1340 3773 5601 9331 1096 2132 2989 970 9392 7135 4449 7013 8749 3770 2648 2918 7484 1656 7137 3969 2254 447 5039 5549 4248 6666 6186 5000 7652 3733 4540 5120 671 9173 4917 4666 7001 4462 8328 7934 6152 2314 107 6921 8533 4137 6107 25 5341 2379 4...

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 300000 lines

Test #33:

score: 0
Accepted
time: 3306ms
memory: 45636kb

input:

500 300000
2528 7545 4192 5079 4193 4366 4191 9722 8343 8319 8806 3486 7631 214 3218 3613 9546 1040 7157 2311 5562 8029 1542 5695 4024 5187 863 9180 7233 1851 4366 1624 5252 4994 9924 5460 6582 9754 729 6946 7326 2310 9878 4794 1609 6689 1721 774 5671 232 6229 4517 4844 9851 8591 2348 5424 2160 5666...

output:

0
0
44
69
0
0
44
0
69
46
100
119
0
100
0
69
0
44
69
60
90
60
0
44
69
69
100
50
16
29
28
20
0
29
28
84
20
50
50
16
50
29
0
20
0
28
16
29
29
46
0
46
29
0
20
28
57
0
0
28
0
0
28
50
0
28
0
28
29
29
28
0
0
0
0
0
0
0
0
0
0
0
0
0
0
40
0
0
0
40
0
0
0
0
0
0
0
0
40
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
40
0
40
40
0
4...

result:

ok 300000 lines

Test #34:

score: 0
Accepted
time: 3308ms
memory: 45600kb

input:

500 300000
8966 4510 2049 2098 9166 8209 933 678 2898 6269 3194 2853 8315 8688 9688 397 868 2360 6956 1088 5707 1738 1897 7365 5732 4607 4258 4438 4550 1010 5889 6017 8843 8659 6019 9752 1460 8838 8330 3376 4836 7397 7130 6965 1936 2378 5996 5941 9317 2710 4525 2929 3874 2797 7008 6815 2969 1832 354...

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 300000 lines