QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#306139#7417. Honorable MentionJohnAlfnovWA 378ms50276kbC++144.1kb2024-01-16 14:15:102024-01-16 14:15:11

Judging History

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

  • [2024-01-16 14:15:11]
  • 评测
  • 测评结果:WA
  • 用时:378ms
  • 内存:50276kb
  • [2024-01-16 14:15:10]
  • 提交

answer

#include<bits/stdc++.h>
#define MN -2000000000
using namespace std;
int n,q,a[50005];
const long long ZZ=1e10;
struct tubao{
	vector<int>vc;
	vector<int>cv;
}sm[131073][2][2];
long long aa[50005],bb[50005],cc[50005],cz[50005];
tubao hebing(tubao a,tubao b){
	int s1=a.vc.size(),s2=b.vc.size();
	for(int i=1;i<s1;++i)aa[i]=0ll+a.vc[i-1]-a.vc[i];
	for(int i=1;i<s2;++i)bb[i]=0ll+b.vc[i-1]-b.vc[i];
	merge(aa+1,aa+s1,bb+1,bb+s2,cc+1);
	cz[0]=0ll+a.vc[0]+b.vc[0];
	for(int i=1;i<=s1+s2-2;++i)cz[i]=cz[i-1]-cc[i];
	tubao c;
	c.vc.resize(s1+s2-1);
	for(int i=0;i<s1+s2-1;++i)c.vc[i]=max(0ll+MN,cz[i]);
	return c;
}
tubao mini(tubao a,tubao b){
	tubao c;c.vc.resize(max(a.vc.size(),b.vc.size()));
	for(int i=0;i<(signed)c.vc.size();++i)c.vc[i]=MN;
	for(int i=0;i<(signed)a.vc.size();++i)
		c.vc[i]=max(c.vc[i],a.vc[i]);
	for(int i=0;i<(signed)b.vc.size();++i)
		c.vc[i]=max(c.vc[i],b.vc[i]);
	return c;
}
void tudd(int o){
	for(int i=0;i<2;++i)for(int j=0;j<2;++j){
		int sz=sm[o][i][j].vc.size();
		for(int k=sz-2;k>=(i==0&&j==1);--k)
			sm[o][i][j].cv.emplace_back(sm[o][i][j].vc[k+1]-sm[o][i][j].vc[k]);
	}
}
void build(int l,int r,int o){
	if(l==r){
		for(int i=0;i<2;++i)for(int j=0;j<2;++j){
			sm[o][i][j].vc.resize(2-(i!=0||j!=1));
			sm[o][i][j].vc[0]=(i==0&&j==1?MN:a[l]*j);
			if(i==0&&j==1)sm[o][i][j].vc[1]=(i==0&&j==1?a[l]:MN);
		}
		tudd(o);
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,o<<1);
	build(mid+1,r,o<<1|1);
	for(int i=0;i<2;++i)for(int j=0;j<2;++j)
		sm[o][i][j]=mini(hebing(sm[o<<1][i][0],sm[o<<1|1][0][j]),hebing(sm[o<<1][i][1],sm[o<<1|1][1][j]));
	tudd(o);
}
int az[50005];
int id[50005],SM[1000005],S2[1000005],ls[1000005],rs[1000005],tot=0;
void add(int x,int y,int l,int r,int u,int v){
	if(l==r){
		SM[y]=SM[x]+v,S2[y]=S2[x]+1;
		return;
	}
	int mid=(l+r)>>1;
	ls[y]=ls[x],rs[y]=rs[x];
	if(u<=mid)add(ls[x],ls[y]=++tot,l,mid,u,v);
	else add(rs[x],rs[y]=++tot,mid+1,r,u,v);
	SM[y]=SM[ls[y]]+SM[rs[y]],S2[y]=S2[ls[y]]+S2[rs[y]];
}
pair<int,int>query(int x,int y,int l,int r,int ll,int rr){
	if(l>=ll&&r<=rr)return make_pair(SM[y]-SM[x],S2[y]-S2[x]);
	int mid=(l+r)>>1;
	int a1=0,a2=0;
	if(mid>=ll){
		auto au=query(ls[x],ls[y],l,mid,ll,rr);
		a1+=au.first,a2+=au.second;
	}
	if(mid<rr){
		auto au=query(rs[x],rs[y],mid+1,r,ll,rr);
		a1+=au.first,a2+=au.second;
	}
	return make_pair(a1,a2);
}
pair<long long,int>X[2];
int C;
#define ccv sm[o][i][j].cv
void apply(int o){
	pair<long long,int>X1[2]={{-1e18,0},{-1e18,0}};
	for(int i=0;i<2;++i)for(int j=0;j<2;++j){
		int wz=upper_bound(ccv.begin(),ccv.end(),-C)-ccv.begin();
		int k=sm[o][i][j].vc.size()-wz-1;
		long long h1=X[i].first+sm[o][i][j].vc[k]+1ll*k*C;
		int h2=X[i].second-k;
		X1[j]=max(X1[j],make_pair(h1,h2));
	}
	X[0]=X1[0],X[1]=X1[1];
}
vector<int>ap;
void quer(int l,int r,int o,int ll,int rr){
	if(l>=ll&&r<=rr){
		ap.emplace_back(o);
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=ll)quer(l,mid,o<<1,ll,rr);
	if(mid<rr)quer(mid+1,r,o<<1|1,ll,rr);
}
pair<long long,int>suan(int l,int r,int c){
	if(c>0){
		int dy=upper_bound(az+1,az+n+1,-c)-az;
		if(dy>n)return make_pair(0,0);
		auto au=query(id[l-1],id[r],1,n,dy,n);
		long long he=au.first+1ll*c*au.second;
		int gs=au.second;
		return make_pair(he,gs);
	}
	X[0]=make_pair(0,0);X[1]=make_pair(-1e18,0);C=c;
	for(auto o:ap)apply(o);
	auto au=max(X[0],X[1]);
	return make_pair(au.first,-au.second);
}
int main(){
//	int aa=clock();
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),az[i]=a[i];
	sort(az+1,az+n+1);
	for(int i=1;i<=n;++i){
		int wz=lower_bound(az+1,az+n+1,a[i])-az;
		add(id[i-1],id[i]=++tot,1,n,wz,a[i]);
	}
	build(1,n,1);
//	cerr<<1.0*(clock()-aa)/CLOCKS_PER_SEC<<endl;
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		ap.clear();
		quer(1,n,1,l,r);
		int L=-(r-l+1)*10000,R=-L;
		while(L<=R){
			int mid=(0ll+L+R+2*ZZ)/2-ZZ;
			auto au=suan(l,r,mid);
			if(au.second<k)L=mid+1;
			else R=mid-1;
		}
		auto au=suan(l,r,R);
		long long ans=au.first-1ll*R*k;
		printf("%lld\n",ans);
	}
//	cerr<<1.0*(clock()-aa)/CLOCKS_PER_SEC<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
-1 2 -3 4 -5
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5

output:

4
6
5
2
-3

result:

ok 5 number(s): "4 6 5 2 -3"

Test #2:

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

input:

5 1
7 7 7 7 7
1 5 1

output:

35

result:

ok 1 number(s): "35"

Test #3:

score: 0
Accepted
time: 374ms
memory: 49072kb

input:

25000 25000
-11889 -16468 18402 -13238 14125 12120 -3295 -12106 20152 7478 8575 9968 -13946 -13408 23715 -14670 -21837 12589 7029 20609 2868 12728 -6942 982 5884 -7561 -2058 -7892 7806 16344 14645 13904 7355 9860 15446 -539 24072 21969 19028 -24939 -21911 -11836 21045 -4727 -3882 2138 18513 -4796 -1...

output:

10341941
44514177
6687268
77971944
99605102
107722534
15473041
17383093
62015893
10703102
41214044
22949449
9407209
9022260
39351814
72311292
5178065
42027491
52700848
38135774
37045964
4761513
16326256
16812496
107985169
28306484
46710957
864270
102812861
27960495
50366764
16379719
2791377
21112728...

result:

ok 25000 numbers

Test #4:

score: 0
Accepted
time: 367ms
memory: 50236kb

input:

25000 25000
6000 -3019 -11754 -7445 -8441 7523 7149 -9202 7895 12217 7475 3656 1303 1710 9238 7029 5141 -1777 8992 -2357 5436 8102 4094 -10002 -7052 3213 1387 -41 -5364 -8259 4860 -721 12482 3791 6804 -10687 4462 -7578 -12456 5135 10987 -9087 5706 -8716 10036 9149 -11514 -7407 4623 9555 -4053 6603 -...

output:

34173465
3726494
235962
7075586
30183529
3643608
48804222
7114899
4984843
15646757
1887647
2330595
47535902
239762
6115278
7951919
1734323
2623203
1495055
1420131
10657149
3064884
12169559
9504529
617684
25801604
3732771
6630548
9892438
1190577
24266894
3527999
23386393
33402029
16816797
62284476
37...

result:

ok 25000 numbers

Test #5:

score: 0
Accepted
time: 378ms
memory: 50024kb

input:

25000 25000
-2969 1681 -2312 -367 -2816 2496 -2066 -636 182 -522 1159 3035 -1616 -2017 -727 -64 987 -3044 -721 1871 -465 452 -2136 -636 1252 2947 -2252 -602 1521 1299 -3070 100 -3111 -1212 -1211 132 2798 -467 1610 408 491 520 2182 2323 2984 -1105 458 -384 917 165 1019 -1424 -1740 1838 225 1043 -1643...

output:

3696093
5856268
1569949
43110
361033
1251419
5991586
11948087
10350223
3152434
10667775
4975400
8739958
9585292
6671359
6889903
10775826
200001
7290024
4142281
7861955
7191701
644506
803034
1932372
9842195
6618617
12318124
4618343
5306047
12502164
612289
2157188
11618855
7200073
5016967
2463491
3209...

result:

ok 25000 numbers

Test #6:

score: 0
Accepted
time: 342ms
memory: 49944kb

input:

25000 25000
-240 -760 1554 200 279 1306 -394 1272 967 -1151 -13 1286 994 1110 551 445 1428 -175 -1427 854 927 911 -969 -920 968 -913 -1481 -669 1487 -600 291 -1070 -782 1504 -222 599 -939 1194 1129 -397 -185 627 772 -870 133 -695 -1092 -137 -778 1332 -158 1545 -329 273 1098 -671 947 -1095 257 -1024 ...

output:

5052771
5348425
6990219
1782518
4288908
124491
4603645
662433
3354133
2273603
2117016
908991
3981909
181606
180388
1445473
8334703
3417019
3832988
1156373
751967
816152
207595
5328156
304047
4822038
8095611
4532395
4836019
4415840
779952
5397423
5924339
1559505
2746919
3784667
3664365
1427979
207448...

result:

ok 25000 numbers

Test #7:

score: 0
Accepted
time: 329ms
memory: 49864kb

input:

25000 25000
-235 -315 120 -376 455 154 461 150 -280 -74 -242 -432 -50 25 -303 -327 263 499 -464 -203 333 59 -265 -72 357 -213 2 275 -159 -4 160 -304 -320 103 447 382 -120 -65 364 -351 73 -307 284 -469 -118 -324 -310 93 -347 -48 -286 139 -25 401 105 -479 -377 428 -26 -313 97 -132 78 14 -64 -59 -455 -...

output:

166178
1692049
770543
2394705
1908039
1005349
356998
25023
355550
891075
214103
788750
1008340
1536696
160682
151535
300585
373884
849931
800218
2440857
1009992
311596
635872
2502637
288362
284558
538137
1553207
849175
165203
544829
230264
163844
1284945
801960
371289
637139
1249915
203702
12408
830...

result:

ok 25000 numbers

Test #8:

score: 0
Accepted
time: 322ms
memory: 49240kb

input:

25000 25000
163 -18 16 -124 54 -71 -111 -81 46 27 139 16 -51 -78 36 21 85 -31 49 33 -42 -42 122 81 -25 -43 166 -131 2 -45 154 -68 -76 127 48 124 92 -26 128 44 -22 -95 -80 -52 -64 -113 22 104 -76 58 49 53 -115 70 -159 -67 62 83 69 164 -11 -13 -4 81 -82 -98 68 136 -7 146 17 138 89 89 18 57 143 57 51 1...

output:

494541
25814
267902
153374
150628
206276
98909
261258
5231
645604
828846
372159
655216
2523
152068
199639
515692
443552
753836
15295
70205
795943
704318
398355
396254
15170
495548
103742
129088
19442
870390
146159
8499
270179
380106
191900
682344
4356
559722
372147
426880
529125
46890
161656
291764
...

result:

ok 25000 numbers

Test #9:

score: 0
Accepted
time: 291ms
memory: 50276kb

input:

25000 25000
10 9 3 19 -1 -5 26 11 3 15 -1 -9 23 11 -24 12 -3 21 -20 10 -10 12 -19 -16 11 -2 19 20 18 -23 27 -23 9 2 1 1 16 -24 -23 -10 -13 21 6 -1 -20 -24 -17 20 23 12 -25 -13 -3 -20 13 24 -27 20 19 5 7 7 9 -24 15 17 -27 16 -13 -15 16 -4 7 13 5 -2 16 25 10 -3 -20 -11 22 -1 -5 -16 19 4 -19 15 5 -25 5...

output:

54921
58348
91837
2814
18931
43185
74327
16895
936
59014
117622
124161
120167
3943
29622
6749
86196
11513
98358
48694
34346
87327
44195
21361
94794
23566
21059
113460
121018
5009
2641
1200
27270
37878
32708
43496
39506
33574
58612
6251
5481
10564
78957
79670
49585
21564
100771
40511
716
93538
21835
...

result:

ok 25000 numbers

Test #10:

score: 0
Accepted
time: 256ms
memory: 49220kb

input:

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

output:

3471
9242
14877
3247
25345
1268
12419
4913
9553
3945
12865
6204
24807
103
6552
27546
24866
17021
9674
9271
32781
18711
2582
18824
31679
7479
1569
15391
21198
19186
4196
13914
284
15798
6722
1620
34719
122
33294
1652
5213
16791
20
26381
15749
1627
3923
13190
2548
3981
10159
10964
8728
2814
6359
5167
...

result:

ok 25000 numbers

Test #11:

score: 0
Accepted
time: 211ms
memory: 49124kb

input:

25000 25000
1 1 0 -1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 -1 -1 1 0 0 -1 -1 -1 -1 -1 1 -1 0 0 -1 1 0 -1 -1 -1 1 -1 1 0 0 1 -1 -1 -1 0 0 0 -1 0 1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 1 1 -1 -1 1 1 0 1 1 -1 0 0 1 0 -1 0 -1 -1 0 0 0 -1 1 0 1 0 1 -1 0 0 1 -1 1 -1 -1 0 -1 -1 1 -1 -1 -1 0 -1 1 1 1 -1 -1 -1 1 -1...

output:

3301
6509
1457
3030
6452
5069
2015
1503
25
1728
3800
117
2258
1451
4167
1618
4122
621
741
2797
1172
69
2098
2213
2771
647
5016
2385
2174
992
1724
289
482
291
6135
4240
2734
1510
4180
7432
7297
1991
929
2836
2507
1868
5223
331
3878
1157
333
533
78
2445
1960
6431
1883
215
525
1894
2587
543
5248
40
642...

result:

ok 25000 numbers

Test #12:

score: 0
Accepted
time: 127ms
memory: 50040kb

input:

25000 25000
-11889 -16468 18402 -13238 14125 12120 -3295 -12106 20152 7478 8575 9968 -13946 -13408 23715 -14670 -21837 12589 7029 20609 2868 12728 -6942 982 5884 -7561 -2058 -7892 7806 16344 14645 13904 7355 9860 15446 -539 24072 21969 19028 -24939 -21911 -11836 21045 -4727 -3882 2138 18513 -4796 -1...

output:

87051882
127416946
156123379
155327388
86540841
156123379
152788996
131969751
156123379
111716016
156123379
155098177
82033347
121443037
152920829
57710183
128591152
156123379
135344755
155722784
156123379
155964587
121111574
128072179
148457241
152720039
78217004
152102942
129197020
68552217
156123...

result:

ok 25000 numbers

Test #13:

score: -100
Wrong Answer
time: 46ms
memory: 29000kb

input:

220 24310
13015 261 15901 -7125 -14419 17435 9913 -24051 18306 -4428 480 -13711 19396 -11292 6420 3248 -8598 6774 -17293 3239 -5108 5952 303 16071 -22557 -4018 -13295 -7069 -4337 11124 22372 22680 -3536 5727 4068 8908 18992 5457 -22918 11369 7680 11365 658 22588 -3283 1458 19818 -1087 -19664 1304 72...

output:

13015
13276
29177
22052
29177
39487
34981
56525
67706
74831
25288
75311
34981
19681
96699
94227
92822
79706
76568
110669
113908
83789
94227
136714
136234
107437
136234
132995
123931
14588
91229
113483
135027
194898
202685
97364
230585
153099
219723
194686
219470
266456
255223
289702
282447
291160
27...

result:

wrong answer 875th numbers differ - expected: '-14419', found: '-10000'