QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184066 | #2029. Minimum Cost Paths | paul2008# | 35 | 464ms | 183260kb | C++14 | 2.5kb | 2023-09-20 11:30:29 | 2024-07-04 02:05:15 |
Judging History
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++)
{
Add(root,1,n,0,1); //直接全局+等差数列
int pos=query_greater(root,1,n,c[i]);
if(pos)
update(root,1,n,pos,n,c[i]);
for(auto x:que[i])
ans[x.second]=query_sum(root,1,n,1,x.first);
}
for(int i=1;i<=q;i++)
printf("%lld\n",ans[i]-1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 11044kb
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: 0
Wrong Answer
time: 48ms
memory: 14536kb
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:
15 14861 10237979 988514 1134 5 63513 5476 22 45485 11111 1587 140 7862 224964 593 11964 11241358 1377 1085019 648 1628 104 43753 1076501 211807134 6 386 5015 116326 1 17368559 1 9245432 3586 50280 3 15385 41784 19046 242 1350671 2812 358300 38457 660 3680 83 2315 59140 796 2 3902 46290591 342 3535 ...
result:
wrong answer 1st lines differ - expected: '25', found: '15'
Test #3:
score: 0
Wrong Answer
time: 57ms
memory: 16568kb
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:
869 6400 1190236 586 3296 1740 12 47 485 41268 74 689 7434 449055 29 445 49 175845 638 9316 1059 16626 5446 78 8540 115 24 23885 15123504 34818084 66506 2582 54 22041 20187563 4189884 9152820 13 1000 410058 2915 41 112137 145107 2679306 490 628360 35 7349718 207 232 8267401 191 249 1314063 7398 9099...
result:
wrong answer 1st lines differ - expected: '904', found: '869'
Test #4:
score: 5
Accepted
time: 364ms
memory: 70728kb
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: 0
Wrong Answer
time: 347ms
memory: 70680kb
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:
wrong answer 35839th lines differ - expected: '5373895635', found: '5373823442'
Test #6:
score: 5
Accepted
time: 339ms
memory: 70752kb
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: 347ms
memory: 70808kb
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: 335ms
memory: 70756kb
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: 0
Wrong Answer
time: 105ms
memory: 21588kb
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:
57131 17003944 60361234 145479019 29144349894 1175651 238049 232795899 10265681761 72674062443 7288989 1442618521 1590078883 130630829869 8041172552 251 9469951 285143 1126074237 199409 693487 272407395 1471 2794411199 16853 2418715 6667837813 1983 224782489 1299 11832190485 67512199 775669599 20021...
result:
wrong answer 1st lines differ - expected: '76279962030', found: '57131'
Test #10:
score: 0
Wrong Answer
time: 107ms
memory: 21464kb
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:
76175 1968696899 113818591 2938113040630 119069999 34689071339 40339018 497513 5207 85697 335173 680327 1878844 6718463 2645918 108299 1265274393658 154243424 13871 59926 37584180749 5328132861 5725662 191843999 149192111 138383 41673096194 68687 16828431632 296517 16492474250 106625239 403073 45127...
result:
wrong answer 1st lines differ - expected: '193767054525', found: '76175'
Test #11:
score: 5
Accepted
time: 176ms
memory: 20960kb
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: 0
Wrong Answer
time: 208ms
memory: 21572kb
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:
424460771 82757 17456987 146551808 707 212 28147252 14945 5161 138897 1942 1136 2848107270480 12 140385 69619 902448 84008448 159625606 778 29674031808 6988591 211266283 5238104 4571145 212202743395 139788 17933216 104859196 2401 7361231073391 1981684 6941543840268 4 20500749 441502559 155806 587685...
result:
wrong answer 1st lines differ - expected: '424460799', found: '424460771'
Test #13:
score: 0
Wrong Answer
time: 213ms
memory: 21516kb
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:
535479839546 229861 14211755 239 37373 1825 3 43 15 8103891 396446 9295962493 15095 32587738 83367 3834368341390 402587503 396 1015333 3 4109 107636 79 262275435 4223 5403 37456090 16964 1295123075461 25875646867630 16196386 9577748171723 5 90113786 60060819 17312346302 210151324 14600897762879 5746...
result:
wrong answer 1st lines differ - expected: '535479839572', found: '535479839546'
Test #14:
score: 0
Wrong Answer
time: 227ms
memory: 23636kb
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:
856314283 71 647795 103834 27975792403 26002263736652 72561146 1038515826781 6301 202152 3573 12355 166752 322294103 46204208 217165439334 40247 4932544 9437 50187 1390143826 18652747 102777163652 152975 411139330632 1904 564751 47956202 16684 339 12322788 20397795559416 14458434 8759427664 238114 1...
result:
wrong answer 1st lines differ - expected: '856314316', found: '856314283'
Test #15:
score: 0
Wrong Answer
time: 216ms
memory: 23648kb
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:
2038598 1413 794882358 952190 27076547429 175613205252 65360736 320670647 9190466835 589638736 2098965343 655911 51201 279 2027369 56332439 1803592 15069523 146 13779278 243318995 5957420 29019014 82 815033 1915441153 1333250 4025 6054156444 43836 1023826839 2740631153 755568743 5684 209285 534070 1...
result:
wrong answer 1st lines differ - expected: '2038617', found: '2038598'
Test #16:
score: 0
Wrong Answer
time: 464ms
memory: 183260kb
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:
81415059 575 454611424908580171 69358286419 20708424 108159 4563058599984066 40362458385959497 2178648975 3072830563976651 27561051019043 5734879 154871270385736504 2562880809999 263823868134214249 86729659028309 1000769113836195 676800 10034076649 114980187 7258358415 1673 84709456338467797 1856073...
result:
wrong answer 1st lines differ - expected: '81415946', found: '81415059'
Test #17:
score: 5
Accepted
time: 320ms
memory: 68064kb
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: 0
Wrong Answer
time: 382ms
memory: 83020kb
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:
163799763397 278247 17280431765319 244706880214 247180183789515 338517796 64892 65763411 19105 13497022779365 83344530 2858233047271750 292803588587 2119050704 529698890587054 63078448745 308140641 20206828333 387835 47110288 20597113 260161 12 18191209 3161978 340201591444 4811200122 7344772509197 ...
result:
wrong answer 1st lines differ - expected: '163799763406', found: '163799763397'
Test #19:
score: 0
Wrong Answer
time: 380ms
memory: 87008kb
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 37913 1648995 1128100814447265 86719036800 221518754986692 17518099043 1104687 1209717022523 504597036151 41814134 10597099 16353 3204979 64187112860 2551930174 22450176 1371379215 53577054 3924211353 167 1037504 1421961 246448451580 650975736 64367 21879606352880 216092 2462282 552877252669...
result:
wrong answer 2nd lines differ - expected: '37932', found: '37913'
Test #20:
score: 0
Wrong Answer
time: 372ms
memory: 89104kb
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:
507 74772 207943990247 433946447173 142543377 73965757579630 2735841916 443569 431760853960 1854727991404 7772593 15036645 39048646290609 7029 35285454321 330378259649 7527230 80918389036 147085334 78629493431 1341273072 38248 3375340819547 251161056 73636580 851260967955 30489 94939982763 3235647 4...
result:
wrong answer 1st lines differ - expected: '510', found: '507'