QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#8720 | #563. 博弈 | LCGUO | 100 ✓ | 218ms | 14716kb | C++20 | 3.8kb | 2021-04-03 20:50:32 | 2021-12-19 10:53:00 |
Judging History
answer
#include<cstdio>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
const int N=100010,M=262150,inf=~0U>>1,BUF=10000000;
char Buf[BUF],*buf=Buf;long long ans;
int n,m,i,x,y,pos[N];bool used[N];
P ma[M],mi[M];int f[M],tag[M];
struct E{int a,b,p;}e[N];
inline bool cmp(const E&a,const E&b){
if(a.b!=b.b)return a.b>b.b;
return a.p<b.p;
}
inline void read(int&a){for(a=0;*buf<48;buf++);while(*buf>47)a=a*10+*buf++-48;}
inline void up(int x){
ma[x]=max(ma[x<<1],ma[x<<1|1]);
mi[x]=min(mi[x<<1],mi[x<<1|1]);
}
void build(int x,int a,int b){
if(a==b){
ma[x]=P(-inf,a);
mi[x]=P(inf,a);
f[x]=-(a+1)/2;
return;
}
int mid=(a+b)>>1;
build(x<<1,a,mid),build(x<<1|1,mid+1,b),up(x);
f[x]=max(f[x<<1],f[x<<1|1]);
}
inline void tag1(int x,int p){f[x]+=p;tag[x]+=p;}
inline void pb(int x){if(tag[x])tag1(x<<1,tag[x]),tag1(x<<1|1,tag[x]),tag[x]=0;}
void maketag(int x,int a,int b,int c,int d,int p){
if(c<=a&&b<=d){tag1(x,p);return;}
pb(x);
int mid=(a+b)>>1;
if(c<=mid)maketag(x<<1,a,mid,c,d,p);
if(d>mid)maketag(x<<1|1,mid+1,b,c,d,p);
f[x]=max(f[x<<1],f[x<<1|1]);
}
void setused(int x,int a,int b,int c,int p){
if(a==b){
used[a]=1;
ma[x]=P(-inf,a);
mi[x]=P(p,a);
return;
}
int mid=(a+b)>>1;
if(c<=mid)setused(x<<1,a,mid,c,p);else setused(x<<1|1,mid+1,b,c,p);
up(x);
}
void setunused(int x,int a,int b,int c,int p){
if(a==b){
used[a]=0;
ma[x]=P(p,a);
mi[x]=P(inf,a);
return;
}
int mid=(a+b)>>1;
if(c<=mid)setunused(x<<1,a,mid,c,p);else setunused(x<<1|1,mid+1,b,c,p);
up(x);
}
int askf(int x,int a,int b,int c,int d){
if(c<=a&&b<=d)return f[x];
pb(x);
int mid=(a+b)>>1,t=-inf;
if(c<=mid)t=askf(x<<1,a,mid,c,d);
if(d>mid)t=max(t,askf(x<<1|1,mid+1,b,c,d));
return t;
}
P askmi(int x,int a,int b,int c,int d){
if(c<=a&&b<=d)return mi[x];
int mid=(a+b)>>1;P t(inf,0);
if(c<=mid)t=askmi(x<<1,a,mid,c,d);
if(d>mid)t=min(t,askmi(x<<1|1,mid+1,b,c,d));
return t;
}
P askma(int x,int a,int b,int c,int d){
if(c<=a&&b<=d)return ma[x];
int mid=(a+b)>>1;P t(-inf,0);
if(c<=mid)t=askma(x<<1,a,mid,c,d);
if(d>mid)t=max(t,askma(x<<1|1,mid+1,b,c,d));
return t;
}
inline int findfirstpos(){
int x=1,a=1,b=n,mid;
while(a<b){
pb(x);
mid=(a+b)>>1;
if(f[x<<1]>0)x=x<<1,b=mid;else x=x<<1|1,a=mid+1;
}
return a;
}
inline int findlastneg(){
int x=1,a=1,b=n,mid,ret=n+1;
while(a<b){
pb(x);
mid=(a+b)>>1;
if(f[x<<1|1]<0){
x=x<<1;
b=mid;
ret=mid+1;
}else{
x=x<<1|1;
a=mid+1;
}
}
if(f[x]<0)ret=a;
return ret;
}
inline void additem(int x){
int val=e[x].a+e[x].b,tmp=askf(1,1,n,x,n);
maketag(1,1,n,x,n,1);
if(tmp<0){
setused(1,1,n,x,val);
ans+=val;
return;
}
int o=findfirstpos();
maketag(1,1,n,x,n,-1);
P y=askmi(1,1,n,1,o);
if(y.first>=val){
setunused(1,1,n,x,val);
return;
}
ans+=val-y.first;
setunused(1,1,n,y.second,y.first);
maketag(1,1,n,y.second,n,-1);
setused(1,1,n,x,val);
maketag(1,1,n,x,n,1);
}
inline void delitem(int x){
if(!used[x])return;
ans-=e[x].a+e[x].b;
setunused(1,1,n,x,-inf);
maketag(1,1,n,x,n,-1);
int o=findlastneg();
if(o>n)return;
P y=askma(1,1,n,o,n);
if(y.first<=0)return;
ans+=y.first;
setused(1,1,n,y.second,y.first);
maketag(1,1,n,y.second,n,1);
}
int main(){
fread(Buf,1,BUF,stdin);read(n);
for(i=1;i<=n;i++)read(e[i].a);
for(i=1;i<=n;i++)read(e[i].b),e[i].p=i,ans-=e[i].b;
sort(e+1,e+n+1,cmp);
for(i=1;i<=n;i++)pos[e[i].p]=i;
build(1,1,n);
for(i=1;i<=n;i++)additem(i);
printf("%lld\n",ans);
read(m);
while(m--){
read(x),read(y);
x=pos[x];
delitem(x);
e[x].a=y;
additem(x);
printf("%lld\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 9664kb
input:
50 6 74 37 63 33 79 100 36 16 2 54 66 75 48 71 3 54 7 5 93 21 34 1 58 33 82 75 4 2 88 69 90 69 52 61 44 10 58 65 3 32 54 95 65 32 83 45 33 32 33 29 58 3 58 93 48 48 39 18 95 47 11 98 13 69 39 53 91 6 96 48 77 5 30 48 54 12 46 82 42 30 40 82 47 39 81 58 65 83 38 77 96 51 1 26 78 43 33 3 56 1000 49 47 29 84 30 87 49 61 49 61 3 78 18 31 34 12 30 40 36 83 49 71 29 5 36 40 47 1 31 88 7 7 32 87 41 48 16 36 47 28 7 57 32 27 37 34 35 75 37 10 26 49 5 94 14 42 24 11 50 10 28 99 21 27 3 37 45 16 35 1 31 6...
output:
424 434 474 473 487 487 507 507 496 449 465 475 457 419 412 431 404 401 401 401 401 401 349 349 363 363 334 395 395 373 373 443 443 420 417 345 323 323 323 323 323 350 311 272 272 309 350 339 339 380 380 380 380 375 366 325 366 377 377 377 377 422 427 387 387 374 385 374 377 377 381 381 375 403 438 409 412 439 436 436 436 436 430 430 474 439 447 451 446 446 442 454 423 418 386 406 406 396 379 376 376 358 381 351 379 379 405 405 405 433 385 385 385 391 391 411 413 413 471 481 503 498 481 535 565 ...
result:
ok 1001 numbers
Test #2:
score: 10
Accepted
time: 5ms
memory: 9768kb
input:
100 196 691 634 855 281 665 906 26 78 721 445 247 434 919 341 349 148 330 441 555 269 233 344 988 963 600 211 157 7 11 426 328 606 1000 247 373 88 564 386 287 910 103 648 216 114 432 320 398 275 718 135 578 426 836 372 212 760 161 847 88 439 981 644 872 778 293 529 339 905 624 184 382 341 438 665 36 369 212 131 605 224 5 696 301 231 117 373 929 435 718 812 294 333 383 964 568 249 58 828 395 385 725 39 510 306 639 462 152 699 454 532 795 954 652 322 200 941 138 906 332 839 211 433 886 967 124 817...
output:
7891 7891 8336 8324 8179 8144 7899 7899 8417 8417 8417 7932 8257 8616 8391 8678 8856 9331 9671 9764 9643 10072 9949 9661 9661 9840 9678 10023 9756 9399 9545 9545 10108 10108 10108 9636 9149 9181 9181 9628 9491 9411 9390 9390 9700 10050 10281 10739 10267 9931 9409 9409 8843 8843 8672 8752 8883 8883 9131 9517 9806 10002 10336 10458 10505 10217 10188 10348 10348 10925 11352 11352 11352 11352 11352 11352 11199 11199 11199 11261 11261 11268 11261 10933 10569 10569 10735 10625 10485 10720 10413 10413 ...
result:
ok 10001 numbers
Test #3:
score: 10
Accepted
time: 18ms
memory: 10016kb
input:
32768 27220257 347694493 262993526 258195531 297716531 793383255 148628703 13051254 829030335 201957049 187023073 177826532 700947110 114771762 440198190 740686413 972254239 506083784 301861142 73444480 234021751 409820569 517578613 159784971 771223754 618589641 129935138 729491037 134361378 869784187 137406918 115475894 779334283 901600626 339171041 209637738 14160734 469479799 889373026 935062231 713086143 102435624 594239624 244141884 61202001 845160675 331672754 871357908 431006581 89609763 ...
output:
4120279809319
result:
ok 1 number(s): "4120279809319"
Test #4:
score: 10
Accepted
time: 60ms
memory: 10656kb
input:
90000 61159 11394 64880 52183 54243 29312 38761 46244 37548 61572 9082 21577 18047 61045 65465 58204 5635 39341 5581 3419 65291 42131 38402 778 9581 45427 30809 17942 59717 6012 20217 52637 21874 32033 26563 34811 19624 64780 56228 44640 16428 9600 19563 31996 313 45995 16246 36155 41480 43007 14374 48774 28470 42583 10850 21321 1723 23337 17319 29619 16288 14105 42881 42292 7348 2271 7203 60836 49716 1234 35325 29465 3898 39078 19918 2831 46831 24162 18537 16882 21935 40718 31149 47198 51854 23...
output:
735541409
result:
ok 1 number(s): "735541409"
Test #5:
score: 10
Accepted
time: 33ms
memory: 9916kb
input:
20000 7671 6063 6936 6972 5519 2111 1073 8193 6951 9499 2361 6301 807 7087 3250 5488 9271 4228 7073 567 8100 5066 8505 4854 9518 3296 6182 1282 2284 1789 7817 5452 6844 9264 9952 9568 1070 7336 9538 4664 790 6052 5239 9957 2523 9905 8150 1012 2106 4877 3589 5325 5788 5971 9059 4102 4341 3996 9879 3730 4110 904 6457 9797 4362 1923 1189 9606 5747 3498 281 4411 5011 8983 3441 2690 4545 4423 789 9036 7580 9801 115 5568 7182 2048 2379 6598 9616 3999 8987 5714 8274 6396 8888 8553 6952 6545 6541 2546 6...
output:
25337364 25341089 25341089 25341089 25337141 25334428 25339383 25340001 25335493 25335493 25335773 25336715 25336715 25332620 25332620 25335048 25335048 25335048 25333441 25331836 25332144 25334624 25334624 25336821 25338378 25334059 25334141 25334141 25335362 25337576 25338054 25333889 25332502 25332437 25333074 25328256 25328256 25328256 25330081 25328965 25328642 25328158 25331728 25326754 25326900 25327740 25325056 25330051 25330051 25334427 25338773 25339192 25343426 25340582 25341738 25340...
result:
ok 20001 numbers
Test #6:
score: 10
Accepted
time: 85ms
memory: 10316kb
input:
32767 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 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:
-8113353756 -8112687881 -8112063872 -8111988621 -8111219032 -8111179910 -8110423486 -8109884901 -8109248242 -8108477769 -8108084842 -8107785026 -8106986296 -8106418429 -8106006666 -8105327661 -8104777961 -8104526883 -8103948471 -8103125785 -8102223880 -8102019425 -8101693911 -8101388246 -8100400426 -8100140964 -8099502074 -8099079885 -8098225068 -8098017860 -8097295664 -8097273269 -8096481101 -8095544230 -8095516801 -8095480753 -8094700943 -8094343510 -8093711301 -8092850625 -8092046875 -8091194...
result:
ok 50001 numbers
Test #7:
score: 10
Accepted
time: 101ms
memory: 10720kb
input:
65536 10746 44814 81070 25810 58184 29530 53502 26625 54511 26487 68812 40086 33706 16707 44733 38853 71973 54411 91025 30357 99751 3672 65893 5904 72104 7153 94656 92966 66979 32046 18496 92445 76116 41248 91619 7109 77102 68626 61658 13076 16461 91042 80071 80970 56731 42579 90238 10450 32554 19102 85007 77035 41776 7740 45725 3298 70660 5688 81511 10978 98909 33777 57675 17367 25864 19160 5114 15838 14095 57590 46815 95718 20569 32902 6264 64492 47525 73855 12041 40571 31027 2146 46357 69417 ...
output:
815806366 1772949086 2170010650 3165784798 3459601173 3975833583 4002645616 4783564737 5561517392 5855046057 6446543206 6658461870 7358312471 8078722673 8394669555 9037910694 9936843188 10595217739 11479566805 12212894211 12718676330 13396635693 14221718236 15177821679 15798297607 16354656050 16843955562 17473780935 17671271374 18151973600 18784008827 19550492444 20205499268 20639053237 20927619090 21172372313 21612067309 22536144562 23171705069 23449585158 24186992633 25107240652 25587622944 26...
result:
ok 32769 numbers
Test #8:
score: 10
Accepted
time: 162ms
memory: 12920kb
input:
80000 39972 913 49153 86266 19739 74284 28893 61097 11709 36726 1867 5954 11502 70827 19821 73456 21050 22300 94515 47993 20591 90251 13801 47591 67681 75317 94943 41630 78472 67556 66258 78107 46811 67436 75566 50598 79059 32344 81285 26292 60184 2401 42824 73127 96095 55288 84858 71341 69321 28512 84032 55550 64771 21384 45987 14143 26632 45799 28397 11828 33656 1106 18722 5685 79708 16658 59192 28838 6990 60915 34459 6788 1212 9592 17411 72741 92935 33340 62672 1692 6934 35969 69838 2364 7320...
output:
1004350850 1004348476 1004334197 1004296191 1004248691 1004248691 1004248691 1004248691 1004226307 1004226307 1004226307 1004193616 1004153804 1004153804 1004153804 1004142955 1004124156 1004074990 1004074990 1004027430 1004027430 1003994042 1003976813 1003970439 1003964986 1003964986 1003964986 1003964986 1003950073 1003950073 1003950073 1003950073 1003950073 1003924633 1003924633 1003924633 1003883040 1003877762 1003877762 1003856302 1003825665 1003792506 1003751263 1003710020 1003661586 10036...
result:
ok 80001 numbers
Test #9:
score: 10
Accepted
time: 216ms
memory: 12648kb
input:
100000 65550370 59312542 20314885 58810591 8363361 81136629 25749017 72196255 7227059 71472263 5492167 30270596 68196778 98084055 34967220 29562124 4609262 37734087 57374592 6749042 65422862 41355925 58992649 80840742 91501472 18044457 21150951 22523303 96589957 67053503 90391621 98512682 22781692 93179003 16574516 86529218 61227458 77425920 38445298 58514494 94828667 89469229 59307946 17427744 86384945 23762937 18482664 12923514 14233348 86863362 88902783 74050650 67914018 62187228 2038501 1887...
output:
1254329519799 1254329519799 1254329519799 1254293622735 1254284068692 1254284068692 1254324641119 1254324641119 1254277013134 1254252340157 1254217439581 1254217439581 1254207369642 1254231636813 1254231636813 1254204862049 1254229454731 1254240981806 1254193486369 1254198038149 1254239441677 1254240003549 1254196923659 1254151792514 1254151792514 1254201276411 1254210058938 1254198406138 1254213728349 1254220736373 1254220736373 1254220736373 1254200314582 1254221562230 1254239880295 1254236998...
result:
ok 100001 numbers
Test #10:
score: 10
Accepted
time: 218ms
memory: 14716kb
input:
100000 745947822 75874392 922317238 754308061 858063803 150165520 27131470 276658077 752611847 248326994 831328692 170679940 74859468 432947841 126266327 205241258 290217129 210618184 57600712 854418983 672634664 178908915 596054951 852019800 337080830 175289698 139936887 659122423 177222950 923070389 150802498 284557908 734395682 509145352 222154733 771404869 708044709 282803408 433936011 752765137 616393616 39022528 283202715 45455138 59225642 566447460 957999344 216819020 576095952 444116275 ...
output:
12414972739534 12415159644560 12415159644560 12415185306536 12415340346998 12415340346998 12415044880017 12414814040916 12415138992858 12415249450274 12415428304290 12415428304290 12415428304290 12415428304290 12415550361123 12415865847827 12416308623298 12415842195022 12415497095992 12415222925011 12415222925011 12415222925011 12414901428058 12414603885069 12414603885069 12414653749243 12414653749243 12414653749243 12414829639138 12414829639138 12414860809870 12414809566574 12414979604622 12414...
result:
ok 100001 numbers