QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184079#2029. Minimum Cost Pathspaul2008#100 ✓442ms183408kbC++142.6kb2023-09-20 11:52:082024-07-04 02:05:18

Judging History

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

  • [2024-07-04 02:05:18]
  • 评测
  • 测评结果:100
  • 用时:442ms
  • 内存:183408kb
  • [2023-09-20 11:52:08]
  • 提交

answer

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

const int N=2e5+5;

struct node
{
	int add,cov; //懒惰标记
	int lc,rc; //左右儿子
	long long sum,Max;
};

vector <pair<int,int> > que[N];
node res[N*35];
int c[N],root,cnt;
long long ans[N];

void pushup(int rt)
{
	res[rt].sum=res[res[rt].lc].sum+res[res[rt].rc].sum;
	res[rt].Max=max(res[res[rt].lc].Max,res[res[rt].rc].Max);
}

void Add(int rt,int L,int R,int cov,int add)
{
	if(cov)
	{
		res[rt].cov=cov;
		res[rt].add=add;
		res[rt].Max=cov+(long long)add*(2*R-1);
		res[rt].sum=(long long)cov*(R-L+1)+(long long)add*(L+R-1)*(R-L+1);
		return;
	}

	res[rt].add += add;
	res[rt].Max += (long long)add*(2*R-1);
	res[rt].sum += (long long)add*(L+R-1)*(R-L+1);
}

void pushdown(int rt,int L,int R)
{
	if(res[rt].cov || res[rt].add)
	{
		if(!res[rt].lc)
			res[rt].lc=++cnt;

		if(!res[rt].rc)
			res[rt].rc=++cnt;

		int mid=(L+R)/2;
		Add(res[rt].lc,L,mid,res[rt].cov,res[rt].add);
		Add(res[rt].rc,mid+1,R,res[rt].cov,res[rt].add);
		res[rt].cov=res[rt].add=0;
	}
}

void update(int& rt,int l,int r,int ql,int qr,int k)
{
	if(!rt)
		rt=++cnt;

	if(ql<=l && r<=qr)
	{
		Add(rt,l,r,k,0);
		return;
	}

	pushdown(rt,l,r);
	int mid=(l+r)/2;
	if(ql<=mid)
		update(res[rt].lc,l,mid,ql,qr,k);
	if(mid+1<=qr)
		update(res[rt].rc,mid+1,r,ql,qr,k);
	pushup(rt);
}

long long query_sum(int rt,int l,int r,int ql,int qr)
{
	if(!rt)
		return 0;

	if(ql<=l && r<=qr)
		return res[rt].sum;

	pushdown(rt,l,r);
	int mid=(l+r)/2;
	long long ans=0;
	if(ql<=mid)
		ans += query_sum(res[rt].lc,l,mid,ql,qr);
	if(mid+1<=qr)
		ans += query_sum(res[rt].rc,mid+1,r,ql,qr);
	return ans;
}

int query_greater(int rt,int l,int r,int val)
{
	if(res[rt].Max<val)
		return 0;

	if(l==r)
		return l;

	pushdown(rt,l,r);
	int mid=(l+r)/2,lans=query_greater(res[rt].lc,l,mid,val);
	return lans?lans:query_greater(res[rt].rc,mid+1,r,val);
}

int main()
{
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=m;i++)
		scanf("%d",&c[i]);

	int q;
	cin >> q;
	for(int i=1;i<=q;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		que[y].push_back(make_pair(x,i));
	}

	root=1, cnt=1;
	for(int i=1;i<=m;i++)
	{
		if(i>1)
			Add(root,2,n,0,1); //直接全局+等差数列
		else
			Add(root,2,n,c[i],0); //直接全局覆盖

		int pos=query_greater(root,2,n,c[i]);
		if(pos)
			update(root,2,n,pos,n,c[i]);

		for(auto x:que[i])
			if(x.first==1)
				ans[x.second]=i-1;
			else
				ans[x.second]=query_sum(root,2,n,2,x.first)+i-1;
	}

	for(int i=1;i<=q;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 0ms
memory: 12120kb

input:

5 4
1 100 100 20
20
1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
1 3
2 3
3 3
4 3
5 3
1 4
2 4
3 4
4 4
5 4

output:

0
1
2
3
4
1
5
11
19
29
2
9
20
35
54
3
13
29
49
69

result:

ok 20 lines

Test #2:

score: 5
Accepted
time: 55ms
memory: 14740kb

input:

2000 2000
1 1 1 1 1 1 1 5 1 2 1 1 4 1 8 1 1 1 11 7 32 28 3 37 41 48 48 32 31 55 17 40 64 65 48 32 61 46 56 72 116 59 90 44 61 54 64 136 118 60 130 98 146 154 124 144 130 63 148 148 137 122 230 199 239 148 214 235 257 262 188 276 210 224 276 201 295 262 162 225 280 310 279 308 311 383 325 312 265 445...

output:

25
14881
10237999
988534
1139
9
63533
5496
27
45505
11131
1607
151
7882
224984
613
11984
11241378
1397
1085039
651
1648
124
43773
1076521
211807154
6
406
5035
116346
4
17368579
5
9245452
3606
50300
9
15405
41804
19066
262
1350691
2832
358320
38477
680
3686
87
2328
59160
801
8
3922
46290611
362
3555
...

result:

ok 200000 lines

Test #3:

score: 5
Accepted
time: 56ms
memory: 14924kb

input:

2000 2000
1 1 1 1 1 1 1 3 1 8 1 1 5 7 1 4 1 8 14 8 40 1 30 16 33 30 23 28 2 24 31 52 4 24 49 1 4 50 10 50 103 82 92 84 55 45 62 100 80 125 131 117 94 143 65 124 63 104 69 76 226 146 131 161 239 246 160 178 254 209 248 242 201 196 208 161 225 222 187 279 389 370 298 274 322 275 333 293 435 355 359 33...

output:

904
6435
1190271
592
3312
1775
20
47
491
41303
88
703
7469
449090
43
456
51
175880
665
9351
1094
16661
5481
78
8575
117
38
23920
15123539
34818119
66541
2617
64
22076
20187598
4189919
9152855
17
1003
410093
2950
55
112172
145142
2679341
493
628395
56
7349753
242
235
8267436
201
252
1314098
7433
9099...

result:

ok 200000 lines

Test #4:

score: 5
Accepted
time: 359ms
memory: 70752kb

input:

1000000000 200000
3 1000000000 999990893 999990333 999985081 999977767 999972028 999967702 999964821 999957604 999954630 999951759 999945888 999944174 999936290 999926683 999921422 999917746 999917576 999917453 999915840 999910322 999906639 999899755 999898806 999893506 999892205 999889172 999888546...

output:

93048058754690
112465352156520661
1769782173967479
16413
87322795288325
9835305145127536
15582838018137
48192
4474760929099819
3094735261472
496076491801144881
8360767
2509216153127887
4827
327267056051098318
1315480086240
335473462937
142307
758354841926
10315
393770074071694673
5024480486098
1887
...

result:

ok 200000 lines

Test #5:

score: 5
Accepted
time: 330ms
memory: 70772kb

input:

1000000000 200000
3 1000000000 999995224 999994164 999984251 999978283 999977190 999977136 999971754 999962090 999954077 999953337 999944089 999941723 999934697 999928129 999918274 999916802 999911461 999904873 999896738 999894431 999893134 999890460 999882614 999875616 999872423 999864204 999861303...

output:

46506043374081
2616797496137799
7266933
21610631547
64164
320775939424768505
5261503
167555001057
285656033191
1807788171745221
244978765737
45143690347717009
96829782
19907113390542
90750106107
54961
11582824156624104
824002846707037
4472929917
638289512
753881
51030979145
236317960182994301
665176...

result:

ok 200000 lines

Test #6:

score: 5
Accepted
time: 356ms
memory: 70820kb

input:

1000000000 200000
3 1000000000 999991486 999981766 999976784 999971384 999967247 999962605 999954863 999952245 999944446 999935072 999933232 999926866 999926508 999917163 999912995 999911320 999910282 999902994 999897400 999891313 999884031 999879635 999872168 999868782 999862129 999858324 999849475...

output:

190014808270134
8021306913
1183786925298919
88063729493
1750604541
190583932569
803593813617771
5991827073027
32848088775833
27
41911179855
56588713
32190
729784508543101
78280503123
43377
7725359408315707
2355398
1625671869714483
30624
753852687
1335806
10009
149942569
333296443443001745
2164407801...

result:

ok 200000 lines

Test #7:

score: 5
Accepted
time: 359ms
memory: 70820kb

input:

1000000000 200000
3 1000000000 999990957 999983325 999978919 999976605 999971359 999966791 999960902 999953591 999948715 999939237 999933153 999927901 999927473 999918348 999913133 999908978 999905504 999897688 999890236 999889555 999881171 999876934 999869706 999861968 999856787 999856139 999849944...

output:

82992319
396508533
65466519737818987
84600090203808
332279
1490372053985189
116414530594569
50640443990722
37995763
663374374506854769
114
585214633649412
14613
730072
3161060091406423
212251497
5645068176679233
199961484292193
5398554225964547
54940111457246450
2783188863119968
10508047
32080648737...

result:

ok 200000 lines

Test #8:

score: 5
Accepted
time: 364ms
memory: 70640kb

input:

1000000000 200000
3 1000000000 999997864 999994431 999988155 999986495 999980513 999979440 999971737 999968982 999962950 999953596 999952790 999948751 999948220 999939491 999939481 999933726 999928543 999926861 999921112 999914865 999914690 999905547 999901263 999892611 999890346 999885103 999877902...

output:

1103332517
20427229361372691
228015
265625
1585483470
1869963
622619091361838826
911942305424029685
6730872994978150
7064250
36285
173304882236004
19212384277911
213543536287625
54305212101
6682
47473822
201038105110165047
179325275259498
7557
1759914674367558
6206464839759
30232392
7597525
53580171...

result:

ok 200000 lines

Test #9:

score: 5
Accepted
time: 128ms
memory: 21600kb

input:

200000 200000
836928809 731939461 556788044 353546603 350398812 565254149 593555454 606090526 74539453 169606212 264614251 529671433 344082061 270428180 97052708 49681369 774482819 203896331 803868124 27181273 123894022 479228608 89591553 525765979 568328479 204369020 739500845 253785869 442847289 4...

output:

76279962030
17003944
72837158
146375211
29144362533
1050185588
251787174585
232907611
10265841564
72674174155
7357069
1442955431
1590975075
130643305793
8042068744
27181464
2820086018
76036589732
1126970429
734961
706126
273303587
31186054
33690780686
18220741037
3198683
6667878469
190269634
2256786...

result:

ok 200000 lines

Test #10:

score: 5
Accepted
time: 128ms
memory: 21476kb

input:

200000 200000
704607471 790824111 684887531 350919959 584747303 684505378 887235108 764616054 1233483 783787575 632548936 958638409 241975493 209675206 179696995 232207356 255754212 548391298 902555004 531412974 394766213 652334186 179826409 798430222 976469763 221361857 791029133 313795280 63409822...

output:

193767054525
12204660683
128695061
2938113083811
976864625
64600302755
55215488
658032
5207
145149181875
495692
691556
214763390680
1064495837
33859772
129443743361
1265289270128
315739144
19747007
4708480
69966823835
5343009331
5832739
1264235249
4385325611
8612497
41673107423
13635713
17001873052
...

result:

ok 200000 lines

Test #11:

score: 5
Accepted
time: 183ms
memory: 21044kb

input:

200000 200000
1 2 5 10 17 26 37 50 65 82 101 122 145 170 197 226 257 290 325 362 401 442 485 530 577 626 677 730 785 842 901 962 1025 1090 1157 1226 1297 1370 1445 1522 1601 1682 1765 1850 1937 2026 2117 2210 2305 2402 2501 2602 2705 2810 2917 3026 3137 3250 3365 3482 3601 3722 3845 3970 4097 4226 4...

output:

716436996919
16668328665
20027435
193438070
10301443263
175079519
3169868943059
83978870
15735329811759
3779032187623
3071485133142
4497128574763
21959407269
367020863
9472811
404543411
318851588727
105321261504662
45388547114
396970095
11830959
6575194
6531556627
6666994
1162892251047
7215494415
39...

result:

ok 200000 lines

Test #12:

score: 5
Accepted
time: 197ms
memory: 23640kb

input:

200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 21 5 23 13 3 19 1 8 30 24 20 7 26 26 36 21 30 22 65 68 84 45 53 64 62 87 69 76 98 72 63 73 79 93 59 100 59 102 135 170 176 176 151 134 184 150 187 183 171 178 165 212 157 154 155 194 229 230 318 304 303 320 289 270 261 294 273 280 296 331 302...

output:

424460799
82761
17457015
146551836
712
240
28147280
14961
5189
138925
1957
1156
2848107270508
27
140395
69647
902476
84008476
159625634
779
29674031836
6988619
211266311
5238132
4571173
212202743423
139816
17933244
104859224
2429
7361231073419
1981712
6941543840296
32
20500777
441502587
155834
58768...

result:

ok 200000 lines

Test #13:

score: 5
Accepted
time: 232ms
memory: 23548kb

input:

200000 200000
1 1 1 1 2 3 4 1 5 1 1 10 1 1 1 1 1 8 5 18 33 11 40 4 2 38 1 3 45 37 60 15 55 41 16 45 53 33 28 18 57 93 73 104 119 84 66 109 66 50 82 91 65 91 102 159 77 119 69 62 239 144 227 145 139 143 174 151 261 223 256 148 144 153 169 199 290 261 265 271 325 344 327 334 359 315 276 360 424 283 38...

output:

535479839572
229877
14211781
249
37399
1851
29
66
38
8103917
396472
9295962519
15096
32587764
83393
3834368341416
402587529
410
1015359
12
4135
107662
82
262275461
4226
5406
37456116
16967
1295123075487
25875646867656
16196412
9577748171749
12
90113812
60060845
17312346328
210151350
14600897762905
5...

result:

ok 200000 lines

Test #14:

score: 5
Accepted
time: 238ms
memory: 25580kb

input:

200000 200000
1 4 1 12 16 1 9 10 27 24 35 1 1 28 12 12 35 58 1 75 8 27 105 95 26 22 121 76 73 55 138 49 33 31 128 3 52 48 42 137 91 115 180 119 216 197 263 238 178 222 136 242 105 80 183 209 287 134 62 249 253 299 136 141 144 227 302 321 276 139 400 484 419 270 422 330 325 533 184 360 482 345 492 48...

output:

856314316
83
647813
103867
27975792436
26002263736685
72561179
1038515826814
6306
202185
3606
12388
166785
322294136
46204241
217165439367
40280
4932577
9470
50220
1390143859
18652780
102777163685
153008
411139330665
1916
564784
47956235
16684
372
12322821
20397795559449
14458467
8759427697
238147
1...

result:

ok 200000 lines

Test #15:

score: 5
Accepted
time: 226ms
memory: 25588kb

input:

200000 200000
1 5 3 11 22 18 41 37 63 24 1 73 70 48 76 56 37 55 17 1 135 14 148 205 94 93 210 84 120 276 48 168 44 21 84 250 184 147 293 135 143 375 189 267 387 84 78 127 454 305 396 87 455 111 87 238 540 328 257 178 190 443 434 584 568 589 697 190 494 521 668 600 567 614 782 321 778 832 325 902 307...

output:

2038617
1432
794882377
952209
27076547448
175613205271
65360755
320670666
9190466854
589638755
2098965362
655930
51211
279
2027388
56332458
1803611
15069542
165
13779297
243319014
5957439
29019033
82
815052
1915441172
1333269
4044
6054156463
43855
1023826858
2740631172
755568762
5684
209304
534089
1...

result:

ok 200000 lines

Test #16:

score: 5
Accepted
time: 442ms
memory: 183408kb

input:

1000000000 200000
966277270 179221972 147871083 903511077 5002193 325361583 742605361 991535375 455636173 843251280 957709410 611724610 663453854 198526499 55570910 922042601 133801610 589927857 886621380 774136032 202722685 731857077 592182750 65486957 337337023 985393628 78916532 821319946 6635752...

output:

81415946
1626582059
454611424908581058
589143284965
20740265
255206487
4563064876514118
40363709477697771
59863409099
3072830563977538
5072821354959470
5735766
154871270385737391
3763978248111
263823868134215136
87139919652831
1000769113837082
708641
106367525821
115140010
111526827929
2560
84709456...

result:

ok 200000 lines

Test #17:

score: 5
Accepted
time: 313ms
memory: 67984kb

input:

1000000000 200000
1 2 5 10 17 26 37 50 65 82 101 122 145 170 197 226 257 290 325 362 401 442 485 530 577 626 677 730 785 842 901 962 1025 1090 1157 1226 1297 1370 1445 1522 1601 1682 1765 1850 1937 2026 2117 2210 2305 2402 2501 2602 2705 2810 2917 3026 3137 3250 3365 3482 3601 3722 3845 3970 4097 42...

output:

6533545530488182
137548664120423511
69542173122741
6932118441
103134511901791
682760556291159
17583369439
8923729532089497
2696537968815
34861088767112647
10762192354159
1785860062531
126481890988831
56313135
260733918077
261474259239326
6428953389084
30259286172817
7353319263
29646
7041604299358
19...

result:

ok 200000 lines

Test #18:

score: 5
Accepted
time: 417ms
memory: 82916kb

input:

1000000000 200000
1 1 59 88 50 13 185 246 36 1 277 151 405 37 502 333 97 136 399 54 51 360 156 102 281 757 159 923 481 577 185 949 555 860 860 918 937 1206 1037 333 1312 583 788 519 568 743 404 796 1753 370 260 902 1845 1951 711 653 125 75 1618 1770 368 1798 990 304 673 1663 1593 1675 1926 2363 245 ...

output:

163799763406
278256
17280431765328
244706880223
247180183789524
338517805
64901
65763420
19114
13497022779374
83344531
2858233047271759
292803588596
2119050713
529698890587063
63078448754
308140650
20206828342
387844
47110297
20597114
260170
13
18191218
3161987
340201591453
4811200131
7344772509206
...

result:

ok 200000 lines

Test #19:

score: 5
Accepted
time: 416ms
memory: 87204kb

input:

1000000000 200000
1 25 18 108 169 26 204 319 43 236 370 311 166 323 485 606 276 783 844 514 391 599 846 90 217 1116 1043 1036 1392 1257 161 291 1346 565 542 871 18 126 1900 1764 1579 1494 1572 803 385 1105 155 780 2160 1223 2109 2573 939 855 1424 719 2681 1239 1886 114 1753 1593 2869 1313 872 1899 2...

output:

2949695
37932
1648995
1128100814447284
86719036819
221518754986711
17518099062
1104687
1209717022542
504597036170
41814134
10597118
16353
3204998
64187112879
2551930193
22450195
1371379234
53577054
3924211372
167
1037523
1421961
246448451599
650975755
64367
21879606352899
216111
2462282
552877252688...

result:

ok 200000 lines

Test #20:

score: 5
Accepted
time: 420ms
memory: 89220kb

input:

1000000000 200000
1 4 26 1 16 178 201 169 127 83 548 330 166 581 685 406 275 968 918 238 93 586 750 1026 560 1301 1048 1708 1759 595 1666 1145 1674 774 517 130 1553 1323 216 1213 2166 735 1878 797 2518 168 3008 1007 365 488 937 2017 1512 876 203 3333 397 3443 2427 1998 3261 2855 1008 2226 1215 1864 ...

output:

510
74775
207943990250
433946447176
142543380
73965757579633
2735841919
443569
431760853963
1854727991407
7772596
15036648
39048646290612
7032
35285454324
330378259652
7527233
80918389039
147085334
78629493434
1341273075
38251
3375340819550
251161059
73636583
851260967958
30492
94939982766
3235650
4...

result:

ok 200000 lines