QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499513 | #8739. 古明地枣的袜子 | zyxawa | AC ✓ | 5682ms | 43072kb | C++14 | 1.7kb | 2024-07-31 15:09:17 | 2024-07-31 15:09:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y,k;
node(int x=0,int y=0,int k=0):x(x),y(y),k(k){}
bool operator<(const node &p)const{return x!=p.x?x<p.x:k<p.k;}
}a[500010],c[500010],q[500010];
int n,m,d,cl[500010],pl[500010],pr[500010];
long long ans[500010],f[710][710],g[710][710],s[500010];
void solve(int l,int r){
if(l==r) return (void)(f[l-d][l-d]=cl[l]-cl[l-1]?a[l].y:-1e18);
int m=(l+r)/2;
solve(l,m),solve(m+1,r),s[m]=0,pl[l-1]=l-1,pr[l-1]=m;
for(int i=m+1;i<=r;i++) s[i]=s[i-1]+a[i].y;
for(int i=l,j=m+1,k=l;i<=m||j<=r;){
c[k]=j>r||i<=m&&a[i].k<a[j].k?a[i++]:a[j++];
pl[k]=i-1,pr[k++]=j-1;
}
for(int i=l;i<=r;i++) a[i]=c[i];
for(int i=l;i<=r;i++) for(int j=i;j<=r;j++) g[i-d][j-d]=f[i-d][j-d],f[i-d][j-d]=-1e18;
for(int i=l;i<=r;i++){
for(int j=i;j<=r;j++){
int l1=pl[i-1]+1,r1=pl[j],l2=pr[i-1]+1,r2=pr[j];
if(cl[m]-cl[l-1]) f[i-d][j-d]=max(f[i-d][j-d],g[l1-d][r1-d]+s[r2]-s[l2-1]);
if(cl[r]-cl[m]) f[i-d][j-d]=max(f[i-d][j-d],g[l2-d][r2-d]);
}
}
}
void calc(int l,int r){
solve(l,r);
for(int i=0;i<=n;i++) s[i]=0;
for(int i=r+1;i<=n;i++) s[a[i].k]+=a[i].y;
for(int i=1;i<=n;i++) s[i]+=s[i-1];
for(int i=0,j=l;i<=n;) j<=r&&a[j].k<=i?j++:pl[i++]=j-1;
for(int i=1;i<=m;i++) if(cl[r]-cl[l-1]) ans[i]=max(ans[i],f[pl[q[i].x-1]+1-d][pl[q[i].y]-d]+s[q[i].y]-s[q[i].x-1]);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y),a[i].k=i;
a[n+1]=node(n,0,n+1),n++,sort(a+1,a+1+n);
for(int i=1;i<=m;i++) scanf("%d%d",&q[i].x,&q[i].y),ans[i]=-1e18;
for(int i=1;i<=n;i++) cl[i]=cl[i-1]+(a[i-1].x!=a[i].x);
for(int i=1;i<=n;i+=700) d=i-1,calc(i,min(i+699,n));
for(int i=1;i<=m;i++) printf("%lld\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 32168kb
input:
6 5 6 4 2 6 5 -5 3 6 1 2 3 6 1 6 1 6 2 6 2 6 5 6
output:
19 19 15 15 8
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 4581ms
memory: 42996kb
input:
500000 499993 388621 -1 431241 -2 98684 -3 225542 3 302101 -1 268099 0 335498 5 207789 -3 178315 5 79438 10 240218 -3 162624 -8 235325 4 366696 13 344613 8 364410 6 433264 16 279350 13 92961 -11 98083 7 278073 -12 378295 -20 403246 -20 373345 17 442503 -21 426711 16 128318 -14 397427 1 35401 11 1680...
output:
38583073 46401789 46136078 44760222 54466220 35576165 38932387 62596992 40282660 68765202 66880455 64517190 53487001 62837204 53990440 37994203 52079234 51079471 48954532 51246090 63117393 42825167 37042281 50091152 47486246 43626097 44097716 34496260 49867623 60357202 50846745 43287850 65491030 590...
result:
ok 499993 lines
Test #3:
score: 0
Accepted
time: 5666ms
memory: 42936kb
input:
500000 500000 460690 334751 484680 228847 381533 -345167 59764 263144 181478 391597 344444 -172316 469660 -73203 323170 -20371 479733 -284856 248504 -324443 199974 -387690 180081 -230691 92925 453600 463189 346973 885 -193592 464248 -218780 134467 -435168 168391 -280787 454903 -72851 167010 221459 6...
output:
164482050 55616876 195448624 45911421 47632376 194159968 38772536 35573615 270902051 192061033 65485396 90209790 69892762 52813843 164473247 143203103 86564257 237271706 156325846 216941080 110243046 45890573 33351500 214560514 146017583 104405888 160880344 147410258 42917968 49743408 58818923 57733...
result:
ok 500000 lines
Test #4:
score: 0
Accepted
time: 5240ms
memory: 43072kb
input:
499995 499990 449160 -94160 96912 313857 136215 88032 395536 77247 79848 -461846 68073 403666 192382 -271083 321684 498493 482456 -54878 48483 159902 409604 -354226 166110 -58526 384502 -457355 130930 453799 240825 -212169 54733 286008 236090 -1177 70772 -237815 11057 95693 323748 95740 299557 31065...
output:
12819561 21141640 81973143 64004804 112968353 101751279 134451883 108132480 77406711 137666443 127830811 71835383 79909923 69884165 97062469 48314499 106984313 52772306 162938162 95465491 175007799 74847507 45029539 20826655 64628779 77735319 34965864 77164437 43017721 94319986 103035323 86007739 38...
result:
ok 499990 lines
Test #5:
score: 0
Accepted
time: 5646ms
memory: 42900kb
input:
500000 500000 186058 -1 76718 -1 348254 3 468052 1 412949 2 424581 4 52350 -7 465145 -6 347630 -9 318246 -6 369352 -11 462861 -6 484170 12 3136 -14 253719 -6 41130 16 416691 11 82545 -10 327995 16 464553 2 467886 -13 62955 10 397422 19 267012 -13 407764 6 68885 -5 451820 -6 425062 13 371736 6 224786...
output:
112104196 104788677 76588880 54958058 45812004 14144830 11644867 71121036 32549765 7504283 367122 31421022 3027826 66805029 100154600 2896774 6177242 5300793 178625 246542 63899786 109703472 53680294 119120667 31038496 12409139 122381008 73770722 71595180 105194800 20763044 68191088 128779130 647445...
result:
ok 500000 lines
Test #6:
score: 0
Accepted
time: 5634ms
memory: 42884kb
input:
500000 500000 352799 -379438 72288 52304 498388 -180921 15831 -185459 437495 403444 410594 161692 150204 -478094 32356 90132 399243 -293793 246394 191734 182327 -124898 273444 149092 197163 376784 99815 -339197 83621 111523 372314 287282 264386 -51444 244376 -457231 251401 -199521 31069 -354198 4489...
output:
48430266 314022104 300864467 106446445 71186392 91898962 146481868 156959045 85297850 21679530 178162780 132121279 67579709 61222681 50194441 35189845 115635732 356943275 199669090 124261044 126237762 41191263 87751116 134121026 126395596 67385603 148809726 259095749 15028619 67689317 109790124 2876...
result:
ok 500000 lines
Test #7:
score: 0
Accepted
time: 5682ms
memory: 43016kb
input:
500000 500000 475882 0 4119 -1 487885 1 220428 3 316327 1 316982 -4 451294 -1 384915 -7 496702 -6 288278 6 442834 -11 235303 10 306369 -1 87609 -2 177976 -13 490642 4 187451 17 23964 -7 193211 -10 222639 3 283491 -13 443137 5 360143 -3 134838 -4 114781 -10 202421 14 62114 -3 486870 21 459431 -7 8049...
output:
86688367 34099134 111432908 2385813 24245240 94887505 110331526 42735627 6269059 41418744 45820970 111165754 3211884 65798286 68919107 28737282 68119419 57161295 115000170 2441944 14258625 60375477 6764716 45028166 71620627 14769210 133163435 116821408 63005349 16859887 92979513 107778370 44888962 1...
result:
ok 500000 lines
Test #8:
score: 0
Accepted
time: 5237ms
memory: 43004kb
input:
500000 500000 347179 -70946 406187 326933 461792 -290500 485956 268019 31833 -168059 488683 91292 183172 397789 412259 -104567 56870 120692 199047 232326 273659 68603 337888 238046 2213 383665 213246 -424333 14723 265433 16927 -157563 195550 170931 201801 -301940 3688 301679 335075 110210 299574 -35...
output:
59411487 28417047 42658132 47225850 37427087 53886317 64584575 87963121 58014467 65276242 125847627 36972104 31339757 35278108 91065532 108892672 40377682 68416412 44665236 55459001 37461464 54624557 62437778 70920781 24722129 42369070 81974315 77085169 52886894 54609923 51740886 29802766 58510632 5...
result:
ok 500000 lines
Test #9:
score: 0
Accepted
time: 5252ms
memory: 43008kb
input:
500000 500000 315961 -1 326005 -2 461590 1 260723 -3 205129 -5 49064 2 259065 -1 248369 -3 35707 1 479372 10 479302 -2 454071 7 153459 9 361489 -5 333252 15 171645 14 3781 -7 75580 16 358854 -19 195655 -7 352590 -12 184982 22 129475 23 101686 -17 233696 10 410459 3 243361 21 152882 -8 496702 -25 178...
output:
20762371 126373639 127096045 122312332 199926647 179474297 91755782 30060888 104481579 117443308 229300244 173648430 160091091 88906931 152013570 164498369 113464247 191125818 151112017 131598527 194518769 155110107 198663024 130840219 105891922 185075640 100355666 130048690 141769734 134816966 1532...
result:
ok 500000 lines
Test #10:
score: 0
Accepted
time: 5258ms
memory: 42996kb
input:
499991 499997 162696 1 338926 2 450378 3 254801 -3 183814 0 285671 0 397566 -6 304361 -1 270137 6 246043 10 107446 -2 377025 5 367654 12 489143 -13 125493 2 351860 -4 418377 12 260443 16 479197 -12 197870 -13 193270 15 411140 -7 366061 -22 102129 -4 365611 4 457724 -20 163029 -11 146833 7 292934 -21...
output:
18488111 17329543 1941016 18435136 21222687 34911115 12596437 8620264 2103903 12864041 19107609 15035697 2117939 21570582 16039458 19074314 2281418 17384131 14832565 20625240 25794855 17048437 17865336 14812100 17061790 9235394 18119157 16946630 13460287 2839615 6563310 18589807 12104209 14247041 81...
result:
ok 499997 lines
Test #11:
score: 0
Accepted
time: 5259ms
memory: 42900kb
input:
500000 500000 3212 -262197 425592 -55118 110982 -414055 479600 -82149 127330 133921 151048 -147548 119937 -49961 350638 362051 315664 -120394 476563 61924 481963 -277722 185454 -208890 181171 -385327 478263 165370 466652 -486283 486741 -224029 66076 23611 42635 -267898 123824 -9988 55463 174551 1677...
output:
5823176 11553849 8596910 22780737 13822207 3750381 75824261 26307568 43025258 2558926 5583807 67966245 39102418 62967603 70941760 104350925 16665556 16575034 23340574 70964476 28740152 121535190 847724 0 38941129 3260667 2971994 96113286 30362017 101673461 85437720 15937254 10633405 2742348 23926147...
result:
ok 500000 lines