QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386101#8540. Splitting Haybalescqbzxzj27.272727 647ms12668kbC++142.0kb2024-04-11 12:00:132024-04-11 12:00:13

Judging History

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

  • [2024-04-11 12:00:13]
  • 评测
  • 测评结果:27.272727
  • 用时:647ms
  • 内存:12668kb
  • [2024-04-11 12:00:13]
  • 提交

answer

// 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int SZ=1<<20;
char buf[SZ],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++)
ll read(){
	ll n=0; bool m=0;
	char c=gc();
	while(c<'0'||c>'9')m=c=='-',c=gc();
	while(c>='0'&&c<='9')n=(n<<3)+(n<<1)+(c^'0'),c=gc();
	return m?-n:n;
}
const int N=2e5+5,B=500;
void f(int &x,int y){x<=0?(x+=y):(x-=y);}
int n,m,a[N],c[N],ql[N],qr[N],qx[N];
ll b[N];
int L[N],R[N],bel[N],bls;
void solve(int l,int r,int pl,int pr){
	if(pl>pr){
		int x=0;
		if(l<=r)for(int i=l;i<=r;i++)c[i]=++x;
		else for(int i=r;i>=l;i--)c[i]=x--;
		return;
	}
	int x=a[pl],y=abs(r-l+1)-a[pl];
	if(l<=r){
		if(x<=y){
			solve(l+a[pl],r,pl+1,pr);
			for(int i=l+a[pl]-1,j=l+a[pl];i>=l;i--,j++)c[i]=1-c[j];
		}else{
			solve(l+a[pl]-1,l,pl+1,pr);
			for(int i=l+a[pl],j=l+a[pl]-1;i<=r;i++,j--)c[i]=1-c[j];
		}
	}else{
		if(x<=y){
			solve(l-a[pl],r,pl+1,pr);
			for(int i=l-a[pl]+1,j=l-a[pl];i<=l;i++,j--)c[i]=1-c[j];
		}else{
			solve(l-a[pl]+1,l,pl+1,pr);
			for(int i=l-a[pl],j=l-a[pl]+1;i>=r;i--,j++)c[i]=1-c[j];
		}
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=b[i-1]+a[i];
	for(int l=1,r=min(B,n);l<=n;l+=B,r=min(r+B,n)){
		bls++,L[bls]=l,R[bls]=r;
		for(int i=l;i<=r;i++)bel[i]=bls;
	}
	m=read();
	for(int i=1;i<=m;i++){
		ql[i]=read(),qr[i]=read(),qx[i]=read();
		int x=qx[i]<=0?-qx[i]:qx[i]-1,l=ql[i]-1,r=qr[i],mid;
		while(l<r){
			mid=(l+r>>1)+1;
			if(b[mid]-b[ql[i]-1]<x)l=mid;
			else r=mid-1;
		}
		f(qx[i],b[l]-b[ql[i]-1]),ql[i]=l+1;
		if(ql[i]<=qr[i]&&bel[ql[i]]!=bel[qr[i]]){
			for(int j=ql[i];j<=R[bel[ql[i]]];j++)f(qx[i],a[j]);
			ql[i]=R[bel[ql[i]]]+1;
		}
	}
	for(int i=2;i<bls;i++){
		solve(1,N-5,L[i],R[i]);
		for(int j=1;j<=m;j++){
			if(ql[j]<=qr[j]&&bel[ql[j]]==i&&bel[ql[j]]!=bel[qr[j]]){
				if(qx[j]<=0)qx[j]=1-c[1-qx[j]];
				else qx[j]=c[qx[j]];
				ql[j]=R[i]+1;
			}
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=ql[i];j<=qr[i];j++)f(qx[i],a[j]);
		printf("%d\n",qx[i]);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4.54545
Accepted
time: 0ms
memory: 7980kb

input:

2
3 1
15
1 1 -2
1 1 -1
1 1 0
1 1 1
1 1 2
1 2 -2
1 2 -1
1 2 0
1 2 1
1 2 2
2 2 -2
2 2 -1
2 2 0
2 2 1
2 2 2

output:

1
2
3
-2
-1
0
1
2
-1
0
-1
0
1
0
1

result:

ok 15 lines

Test #2:

score: 4.54545
Accepted
time: 0ms
memory: 7904kb

input:

5
4 4 3 1 1
7
1 1 20
1 2 20
1 5 20
1 1 0
1 5 0
1 4 0
3 5 2

output:

16
12
7
4
1
2
1

result:

ok 7 lines

Test #3:

score: 0
Wrong Answer
time: 22ms
memory: 11096kb

input:

200000
199998 199997 199996 199995 199994 199994 199993 199992 199992 199991 199991 199990 199990 199988 199987 199986 199986 199985 199984 199983 199982 199980 199979 199979 199976 199976 199975 199974 199974 199974 199974 199972 199971 199970 199970 199970 199969 199968 199968 199967 199967 199967...

output:

-6483
-2874
15469
10928
-152199
-102062
-1
-12287
-26123
-94203962
26393
0
-8076
93272
27502
28955
-5136
-23911
27328
31134
5281
-3115
-76892
29684
111108
338346276
-8552
-603
-78595
27682
-31391
-47131
-2227
-30340
-35467
-24882
42762
-96720663
821
-26095472
-2573
-327
2589
-75022
111439361
-8263
2...

result:

wrong answer 1st lines differ - expected: '-42604', found: '-6483'

Test #4:

score: 0
Wrong Answer
time: 591ms
memory: 12668kb

input:

200000
199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169...

output:

24544
32624
-5717
-149629
-40511
-107547
6157
11159
13869
-15282
-32621
-1628
39113
-32639
23140
31333
-26205
-107538
12212
-27971
30149
26254
12107
27333
-8256
646
6189
700
-32758
-3474
1112
4359
25196
-2
13173
26133
-3572
70
-45106
-1011
-23705
-44013
-26525
580138178
-590
-8771
-4236
1566
-104108...

result:

wrong answer 1st lines differ - expected: '23636', found: '24544'

Test #5:

score: 0
Wrong Answer
time: 594ms
memory: 11088kb

input:

200000
196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702...

output:

33981
1944
-4892
-178757730
40781
-667
4884
-20645
-75074
5770
138304
22269
-53910
-21658
-38722
-133186
40165
-27201
6525
-59867
-92456
6531
-27994
-4624
153093
-26802
-7622
-92305
-11382
-28098
-72219
-202330620
24899
-12557
-80543
36055
29553
26901
-8146
94952
2935
-54183
-11686
6334
3615
-17839
...

result:

wrong answer 1st lines differ - expected: '57359', found: '33981'

Test #6:

score: 4.54545
Accepted
time: 615ms
memory: 12564kb

input:

200000
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

80942
1
79697
-245062
-138409
0
-90287
-58075
0
1
200556
58954
-140119
1
1
326117
-73901
-76225
-97605
-223478
-175026
47817
1
-30451
0
-145315
1
273031
1
132933
0
-71358
-17522
263820
5761
1
130689
363960
0
27845
-337912
1
112360
0
0
-216292
-164215
319627
0
314753
1
-106477
0
-154442
0
-148812
184...

result:

ok 200000 lines

Test #7:

score: 0
Wrong Answer
time: 370ms
memory: 12488kb

input:

200000
200000 199999 199991 199988 199980 199971 199967 199959 199946 199936 199934 199934 199926 199924 199921 199910 199909 199905 199892 199892 199892 199888 199883 199882 199878 199877 199873 199872 199863 199859 199857 199855 199854 199853 199847 199844 199842 199838 199837 199833 199829 199828...

output:

0
683077295
122428774
0
-24298048
128377
937868532
424108432
303866944
-883269967
-719646861
262110842
-342029334
139146496
33866015
278478758
294879742
-440873497
945882552
-520414733
-1
78963615
-423143954
-22832222
1
1
-937595413
672048473
319387351
-238034022
1
0
-69424970
-339394007
0
911609054...

result:

wrong answer 4th lines differ - expected: '2', found: '0'

Test #8:

score: 0
Wrong Answer
time: 373ms
memory: 11084kb

input:

200000
199988 199987 199985 199978 199976 199974 199962 199962 199960 199952 199950 199949 199946 199938 199931 199927 199920 199917 199914 199909 199907 199905 199901 199900 199897 199890 199885 199871 199850 199842 199840 199835 199835 199831 199829 199819 199818 199810 199809 199808 199807 199806...

output:

237395027
-337419074
-189451091
1
-332788862
-1
91628900
-346043662
397302856
-722203477
-111751265
-659185879
23760
140456984
949846049
-379972995
-761374079
-332651862
989297551
-935292485
112011711
-873011453
-410823783
-34289
1
-865505400
-880351232
550473176
465331110
401963958
-357247174
25195...

result:

wrong answer 13th lines differ - expected: '45762', found: '23760'

Test #9:

score: 0
Wrong Answer
time: 631ms
memory: 12576kb

input:

200000
199999 199999 199991 199990 199989 199986 199984 199983 199982 199981 199979 199977 199973 199973 199973 199972 199971 199969 199967 199964 199963 199962 199962 199961 199960 199959 199954 199953 199950 199950 199948 199947 199942 199938 199935 199934 199932 199931 199930 199925 199925 199922...

output:

-618058211
-734050272
1
-11203600
-336722737
-914687519
375284143
4310
1
-395141318
13651
1
10434
0
87990
-1728
-1
0
-2
-169171736
1
-1
-782437547
444544800
-24542
-74335824
-70457261
85128948
-525514559
479010776
0
-33108
-16680
-35411
51401
2688
0
0
-490716962
22200
0
-3693897
-25984536
2
-77384
1...

result:

wrong answer 8th lines differ - expected: '19543', found: '4310'

Test #10:

score: 0
Wrong Answer
time: 638ms
memory: 11220kb

input:

200000
200000 199996 199994 199993 199991 199990 199990 199989 199981 199980 199979 199977 199973 199971 199968 199967 199967 199964 199963 199960 199958 199958 199955 199947 199946 199945 199945 199945 199945 199943 199940 199940 199940 199938 199936 199935 199934 199932 199932 199930 199926 199925...

output:

-263580135
667701968
-7448
2
-70891206
2
647
-1
-61791271
-278009369
0
853497099
0
2
-6789
-640923763
1
1
829743924
-688890570
-289895514
-601120093
0
-386308758
64546
-979451754
753881743
0
-29378
0
-522553562
0
0
0
23469542
-22900
331192702
6159
803694403
-312676299
-255534346
1
-547768221
1314960...

result:

wrong answer 3rd lines differ - expected: '-11224', found: '-7448'

Test #11:

score: 0
Wrong Answer
time: 638ms
memory: 11156kb

input:

200000
199999 199999 199998 199998 199996 199996 199996 199993 199991 199991 199990 199990 199986 199985 199984 199984 199982 199981 199981 199976 199970 199968 199966 199965 199962 199960 199960 199957 199952 199951 199950 199945 199944 199942 199942 199941 199940 199938 199938 199935 199935 199934...

output:

937427738
-1
0
2882
-1
784640227
459728606
396666044
27458
32972702
-136006731
-6043
-664847131
13572628
1
952878858
-30136
147307138
79293988
444804441
-16715
-707856020
927532047
-30563
34786
1
-4444
533243010
-134524396
2
201976994
77884603
-82356160
-372290409
26661
-261006436
-431291287
1733
47...

result:

wrong answer 2nd lines differ - expected: '2', found: '-1'

Test #12:

score: 0
Wrong Answer
time: 644ms
memory: 11156kb

input:

200000
199999 199998 199998 199996 199994 199994 199993 199988 199986 199985 199983 199981 199981 199979 199977 199975 199973 199972 199972 199971 199970 199970 199967 199961 199961 199955 199952 199950 199947 199946 199943 199940 199938 199937 199933 199933 199933 199931 199928 199919 199915 199915...

output:

22101
1
1
-86131
73643
26494
-1
0
1
1
-30543
-211180674
878258016
0
1
123284856
17602
-496232527
-590405448
921105269
-951831643
0
-730770845
-668577548
-108260
-103047809
0
1
2
-4817
155098722
0
1
34392
148517696
-124869
1
11295
-965137204
995406597
-139176917
2
-1802
-1
324278316
-1
329271818
-832...

result:

wrong answer 6th lines differ - expected: '-40151', found: '26494'

Test #13:

score: 0
Wrong Answer
time: 591ms
memory: 12556kb

input:

200000
199999 199999 199998 199998 199996 199996 199993 199992 199992 199992 199990 199989 199989 199989 199989 199988 199988 199986 199985 199982 199982 199981 199979 199978 199978 199978 199977 199977 199976 199975 199975 199972 199972 199971 199970 199969 199969 199967 199964 199964 199963 199963...

output:

3296
29200
-497
28592
26836
-762313731
-128308
31611
31394
78513
46416
-98369
-225539293
6842
-11492
33730
66613
-6226
-4896
-30065
6555
-15826
-9911
-113634
-1
1912
-813362156
2472
-28381
86646
56633
31070
3534
-29764
-65399
-66703
-24484
-434646794
2554
-59127
50301
-47624
18471
22177
-9072
35321
...

result:

wrong answer 1st lines differ - expected: '0', found: '3296'

Test #14:

score: 0
Wrong Answer
time: 601ms
memory: 11116kb

input:

200000
199997 199993 199993 199993 199993 199992 199992 199991 199991 199990 199990 199990 199990 199986 199982 199982 199982 199980 199977 199977 199976 199974 199974 199974 199973 199973 199973 199971 199969 199968 199968 199966 199965 199965 199964 199963 199963 199962 199962 199962 199962 199961...

output:

24233
-55846
29458
-69404
-22898
79128
32013
27034
159285
6627
-30407
844737905
-7313
-25518
-4705
-67237
-52076
44926
941
27297
2279
-8035
-3662
-152828
-7075
3129
45681237
-17588
21639
-73778
19277
-108731
206073603
-873
-1
43991
2248
-495313695
1
-52
-25148
-134419
3409
29443
-130330
-1861
-38210...

result:

wrong answer 1st lines differ - expected: '0', found: '24233'

Test #15:

score: 0
Wrong Answer
time: 596ms
memory: 11172kb

input:

200000
199996 199996 199995 199992 199991 199989 199988 199988 199986 199986 199985 199984 199983 199982 199982 199980 199978 199978 199973 199972 199971 199969 199969 199969 199969 199968 199968 199967 199967 199967 199967 199964 199961 199961 199960 199959 199959 199959 199958 199957 199956 199955...

output:

-17852
-114824
30166
-2352
63907
32431
113641
13992
-1262
-4108
28842
26277
69744
1501
-845
2007
24254
-30725
30676
37877
33293
51838
23408
0
19327
162384
-122833
81442
-4201
16292
11384
27872
-13475
-4321
29595
-107528
-27892
108750
37007
30257
6540
-42477
23343
87578
35107
43487
18715
109883
-1261...

result:

wrong answer 1st lines differ - expected: '-59946', found: '-17852'

Test #16:

score: 0
Wrong Answer
time: 596ms
memory: 11160kb

input:

200000
200000 199998 199996 199995 199993 199989 199988 199986 199985 199985 199985 199984 199979 199978 199977 199976 199974 199970 199969 199968 199968 199968 199966 199965 199964 199963 199963 199963 199961 199961 199961 199959 199959 199958 199958 199957 199956 199956 199955 199954 199954 199952...

output:

-5868
27673
-32624
-30594
-9413
-1546
-2018
-12270
2095
-31605
-28450
-1283
-44889
37209
777
7335
1926
-1681
-43631
-851
1
19108
142316
92283
2731
72650
-1089
-12096
9328
-621006111
-123458
7
-49020
12493
-25539
-18606
-3789
-9148
-18323
2262
71651
-2794
70519
-18608
22703
572
734634912
7186
423
-25...

result:

wrong answer 1st lines differ - expected: '20400', found: '-5868'

Test #17:

score: 4.54545
Accepted
time: 583ms
memory: 11076kb

input:

200000
200000 200000 200000 200000 200000 200000 199998 199998 199998 199998 199996 199996 199996 199996 199996 199996 199994 199994 199994 199994 199992 199992 199992 199992 199992 199992 199990 199990 199990 199990 199990 199990 199988 199988 199988 199988 199986 199986 199986 199986 199984 199984...

output:

25728
-138377
161886
-138451
112828
-1
-118026
1
1
-117133
1
3342
97795
4797
1
-8564
-8987
1
34498
-100174
133383
100715
186477
126889
135751
-158957
-23614
127911
-31065561
1
122439
-1
4858
0
-148417
-165821
-1
138951
153129
-30321
-35278
169513
78435
-144990
-86108
-479774210
-1
-1895
42827
121289...

result:

ok 200000 lines

Test #18:

score: 4.54545
Accepted
time: 583ms
memory: 11176kb

input:

200000
200000 200000 200000 200000 199998 199998 199998 199998 199998 199998 199996 199996 199996 199996 199996 199996 199994 199994 199994 199994 199994 199994 199992 199992 199992 199992 199990 199990 199990 199990 199988 199988 199988 199988 199988 199988 199986 199986 199986 199986 199984 199984...

output:

-1
-34250
-73957
47388
10685
-33900
-151347
1
-4349
1
-15611
-100171
-1
-150845
-1
1
-121137
156682
104147
-63443
-128799
-128019
-155671
-166893
-141287
1
128537
-43126
535923341
80015
133545
1
-137261
1
129149
16186
1
-95455
166718
-122052
-24309
-1
74662
-148883
133071
149941
-182781
121585
1
695...

result:

ok 200000 lines

Test #19:

score: 0
Wrong Answer
time: 634ms
memory: 11156kb

input:

200000
199999 199998 199998 199997 199996 199996 199996 199996 199995 199995 199994 199994 199993 199990 199990 199989 199988 199986 199985 199985 199984 199984 199983 199980 199979 199979 199979 199979 199977 199977 199976 199976 199974 199973 199972 199971 199971 199970 199968 199966 199964 199960...

output:

13228
-1
-946062094
-526108414
261673003
-134632
-97270890
578566247
-184259734
80162
-382956770
71367
1
58205
594690504
-46227
0
0
-454244729
855885103
1
-29065
-25825
70152
1
-1
-112685
-91050
240728375
11567
-24651
-18243
-892814087
-1
-578524011
0
-417803356
-692062748
-194709572
0
-11985
2
0
-3...

result:

wrong answer 2nd lines differ - expected: '1', found: '-1'

Test #20:

score: 0
Wrong Answer
time: 596ms
memory: 11156kb

input:

200000
199998 199995 199994 199993 199993 199992 199992 199991 199988 199986 199985 199985 199982 199981 199979 199978 199978 199977 199977 199977 199975 199975 199973 199971 199971 199970 199969 199968 199968 199967 199967 199963 199963 199962 199960 199959 199958 199958 199957 199956 199956 199954...

output:

32020
189183586
0
603600219
3551
-35840
-23899
7429
1
2443
44288
1744
-79069
35913
24927
-93025
-71483
3814
116969
-39283
-4486
-63503
36197
-142815
-36321
-4752
-31641
29310
-39388
-30393
56483
6265
-71
990
-72231
13339
4543
40754
26897
-58536
-96612
29184
-24783
31076
-1749
27085
150035
-36248
186...

result:

wrong answer 1st lines differ - expected: '4', found: '32020'

Test #21:

score: 0
Wrong Answer
time: 603ms
memory: 11280kb

input:

200000
200000 199999 199999 199998 199996 199995 199994 199994 199993 199991 199990 199989 199988 199988 199985 199985 199981 199980 199980 199980 199980 199979 199979 199978 199975 199973 199972 199970 199969 199969 199969 199968 199968 199966 199965 199965 199963 199961 199961 199961 199958 199958...

output:

765
40922
-30465
44636
-76902
-148726
-42479
0
-67957
93315
32648
-69974
-27214
-5201
205181594
-31507
34414
-27761
-27067
-1996
-9474
29924
-26711
-29201
16771
29099
1015
303934982
2741
-25175
-22807
31405
-4682
-27740
2619
23699
-5214
-123353
-29299
5502
-26196
5402
16406
25877
6222
28189
-4195
24...

result:

wrong answer 1st lines differ - expected: '-20767', found: '765'

Test #22:

score: 4.54545
Accepted
time: 647ms
memory: 11212kb

input:

200000
200000 200000 199999 199997 199997 199996 199996 199995 199992 199991 199990 199989 199988 199988 199987 199987 199987 199986 199984 199984 199983 199982 199982 199982 199979 199979 199979 199974 199973 199972 199972 199970 199969 199969 199969 199967 199967 199965 199964 199961 199960 199956...

output:

0
-116796
139394
0
0
112646
1
18789
0
-17056
-65305
-64209
0
52679
20975
-91367
147879
-27255
1
-50166
-128771
0
-65388
0
1
1
1
-76751
-53483
1
268952
-42058
-141322
-102385
90387
0
131668
337
14265
-207903
-178023
50649
-37056
1
53006
76661
0
-77029
318746
1
1
0
67670
0
0
-99430
12828
0
0
131729
2
...

result:

ok 200000 lines