QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378004 | #5059. Plants vs Zombies | InfinityNS# | AC ✓ | 284ms | 20116kb | C++14 | 5.5kb | 2024-04-05 22:11:58 | 2024-04-05 22:11:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
bool debug=false;
int n,m;
ll V,K,D;
set<pair<int,int>> alive;
const int N=100050;
int t[N],h[N],p[N],a[N],ord[N];
ll sum[N],offs[N];
const ll inf=1e18;
ll ML(ll x,ll y){
if(x==0 || y==0)return 0;
if(inf/x<y)return inf;
return x*y;
}
const ll lim=2e14;
ll tme[N],start,amo;
set<pair<ll,int>> all;
void Recalc(int i){
if(debug)printf("Recalc %i\n",i);
if(tme[i]!=inf)all.erase({tme[i],i});
bool first=false;
if(alive.begin()->second==i)first=true;
if(debug)printf("Is first: %i\n",first);
ll bot=t[i],top=lim,ans=inf;
while(top>=bot){
ll mid=top+bot>>1;
if(debug)printf("mid:%lld\n",mid);
int j=upper_bound(offs+1,offs+1+m,mid-t[i])-offs-1;
if(debug)printf("j:%i\n",j);
ll hpLoss=sum[j];
if(first){
ll st=max(start,(ll)t[i]-1);
if(debug)printf("st:%lld\n",st);
if(mid>st)hpLoss+=ML(ML((mid-st),K),D);
if(debug)printf("hpLoss1: %lld amo:%lld\n",hpLoss,amo);
if(mid>=start && start>=t[i])hpLoss+=ML(amo,D);
if(debug)printf("hpLoss2: %lld\n",hpLoss);
}
if(debug)printf("hpLoss: %lld\n",hpLoss);
if(hpLoss>=h[i]){
top=mid-1;
ans=mid;
}else{
bot=mid+1;
}
}
if(debug)printf("Calc i:%i ans:%lld\n",i,ans);
tme[i]=ans;
if(ans!=inf){
all.insert({tme[i],i});
}
}
ll ans[N];
typedef pair<int,int>pii;
vector<int>brute(){
vector<int>pt(n+1),ph(n+1),pp(m+1),pa(m+1),pos(n+1),rez(n+1);
for(int i=1;i<=n;i++){
pt[i]=t[i];
ph[i]=h[i];
pos[i]=-1;
}
for(int i=1;i<=m;i++){
pp[i]=p[i];
pa[i]=a[i];
}
int alive=n;
for(int x=1;alive;x++){
vector<pii>cand;
for(int j=1;j<=n;j++){
if(pt[j]==x)pos[j]=0;
if(pos[j]==-1)continue;
for(int k=1;k<=m;k++){
//printf("%d | %d %d %d\n",x,pos[j],pos[j]+x,pp[k]);
if(pp[k]>pos[j] && pp[k]<=pos[j]+V){
ph[j]-=pa[k];
//printf("%d %d SKINO\n",x,k);
}
}
if(ph[j]<=0){
rez[j]=x;
//printf("%d %d AA\n",j,x);
pos[j]=-1;
alive--;
}
if(pos[j]!=-1){
pos[j]+=V;
cand.pb({pos[j],-j});
}
}
sort(cand.begin(),cand.end());
for(int i=1;i<=K;i++){
if(cand.size()==0)break;
int id=-cand.back().ss;
ph[id]-=D;
if(ph[id]<=0){
cand.pop_back();
pos[id]=-1;
rez[id]=x;
alive--;
//printf("%d %d AAFF\n",id,x);
}
}
//printf("%d %d %d AFA\n",x,ph[1],pos[1]);
}
return rez;
}
void Solve(){
alive.clear();
all.clear();
for(int i=1;i<=n;i++){
alive.insert({t[i],i});
tme[i]=inf;
}
for(int i=1;i<=m;i++){
ord[i]=i;
}
start=0;
amo=K;
sort(ord+1,ord+1+m,[&](int i,int j){return p[i]<p[j];});
for(int i=1;i<=m;i++){
sum[i]=sum[i-1]+a[ord[i]];
offs[i]=(p[ord[i]]+V-1)/V-1;
}
for(int i=1;i<=n;i++)Recalc(i);
while(all.size()){
int i=all.begin()->second;
ans[i]=all.begin()->first;
all.erase(all.begin());
if(debug)printf("i:%i ans:%lld\n",i,ans[i]);
bool first=alive.begin()->second==i;
if(debug)printf("first:%i\n",first);
alive.erase({t[i],i});
if(first){
int j=upper_bound(offs+1,offs+1+m,ans[i]-t[i])-offs-1;
ll H=h[i]-sum[j];
ll have=0;
ll st=max(start,(ll)t[i]-1);
if(ans[i]>st)have+=ML((ans[i]-st),K);
if(ans[i]>=start && start>=t[i])have+=amo;
ll need=max((H+D-1)/D,(ll)0);
if(debug)printf("have:%lld need:%lld\n",have,need);
amo=min(have-need,K);
start=ans[i];
}
if(debug)printf("start:%lld amo:%lld\n",start,amo);
if(first){
if(alive.size()){
Recalc(alive.begin()->second);
}
}
}
}
mt19937 rng(time(0));
void Gen(){
n=2;
m=rng()%5+1;
V=5;
K=3;
D=2;
int mx=10;
for(int i=1;i<=n;i++){
t[i]=rng()%mx+1;
h[i]=rng()%mx+1;
}
for(int i=1;i<=m;i++){
p[i]=rng()%mx+1;
a[i]=rng()%mx+1;
}
}
void Test(){
for(int test=0;test<100000;test++){
Gen();
printf("%i %i %lld %lld %lld\n",n,m,V,K,D);
for(int i=1;i<=n;i++)printf("%i %i\n",t[i],h[i]);
for(int i=1;i<=m;i++)printf("%i %i\n",p[i],a[i]);
printf("Doing brute\n");
vector<int>bbb=brute();
printf("Doing solve\n");
Solve();
bool ok=true;
for(int i=1;i<=n;i++)if(ans[i]!=bbb[i])ok=false;
if(!ok){
printf("%i %i %lld %lld %lld\n",n,m,V,K,D);
for(int i=1;i<=n;i++)printf("%i %i\n",t[i],h[i]);
for(int i=1;i<=m;i++)printf("%i %i\n",p[i],a[i]);
printf("Brute: ");for(int i=1;i<=n;i++)printf("%i ",bbb[i]);printf("\n");
printf("Solve: ");for(int i=1;i<=n;i++)printf("%lld ",ans[i]);printf("\n");
exit(0);
}
printf("Test %i passed\n",test);
}
}
int main(){
///freopen("test2.txt","r",stdin);
//Test();
//return 0;
scanf("%i %i %lld %lld %lld",&n,&m,&V,&K,&D);
for(int i=1;i<=n;i++){
scanf("%i %i",&t[i],&h[i]);
}
for(int i=1;i<=m;i++){
scanf("%i %i",&p[i],&a[i]);
}
//vector<int>bbb=brute();
//for(int i=1;i<=n;i++)printf("%d ",bbb[i]);
//printf("\n");
Solve();
for(int i=1;i<=n;i++){
/*if(ans[i]!=bbb[i]){
printf("%lld %d\n",ans[i],bbb[i]);
}*/
printf("%lld ",ans[i]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7988kb
input:
3 2 1 2 2 1 11 2 8 1 1 1 2 2 4
output:
2 3 1
result:
ok 3 number(s): "2 3 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 8236kb
input:
1 1 1 1 1 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5920kb
input:
3 3 1 1 2 4 4 1 10 2 4 4 1 4 2 4 1
output:
6 4 5
result:
ok 3 number(s): "6 4 5"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5928kb
input:
3 3 3 1 3 2 2 1 10 3 6 1 1 5 2 5 1
output:
3 2 4
result:
ok 3 number(s): "3 2 4"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7992kb
input:
100 100 1 699 1 695 44646 675 24436 962 82902 293 78650 759 58744 487 49515 768 60962 380 83162 9 92232 502 39702 170 1920 653 66006 595 94263 953 4538 976 49244 39 31995 480 99939 638 92034 926 25555 125 62420 788 96382 917 60564 41 77628 699 61083 145 99923 386 47153 209 82540 477 92571 324 11390 ...
output:
5134 4907 7128 2211 5508 3835 5829 3008 140 3891 1337 4778 4426 7010 7235 354 3765 4684 6793 982 5969 6640 465 5221 1205 3074 1676 3623 2592 5642 778 5071 4435 4292 7005 4109 1775 1335 2023 2446 6154 4873 6363 2027 181 5276 3415 3415 5016 2720 3353 5340 4013 556 619 1446 1063 1559 688 1464 6540 4553...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 8212kb
input:
100 100 1 172 1 259 27711 294 17257 293 24667 444 93715 86 54281 261 84431 434 19704 387 58086 930 85598 812 89476 894 86493 807 93015 915 73948 397 64142 658 31428 317 8414 653 10577 191 99813 693 85189 1 86573 678 61161 979 61001 91 90060 187 33242 751 36675 763 97347 72 58254 780 23104 943 36078 ...
output:
9062 11668 11571 14641 3934 9550 14099 12845 27650 23556 24994 23039 26579 13215 18202 11714 18022 7241 20059 502 18554 28961 4455 6664 21038 22023 3622 22279 28373 5447 26731 661 12160 1679 29159 2331 16377 22148 19002 8356 15168 8118 15170 2637 7819 11767 15839 10928 1352 2031 24286 6473 5988 6408...
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 6208kb
input:
100 100 1 51 13 266 26947 110 58962 533 11873 663 35099 570 32077 380 93730 82 77111 756 74660 83 56780 564 50487 590 14613 979 54268 244 12239 385 7679 842 13960 113 31166 451 57306 120 71138 546 11247 808 91483 72 42229 632 87393 760 88853 771 14456 187 64663 668 56825 405 40219 86 11559 744 38762...
output:
2610 1021 4450 5441 4965 3459 626 5803 712 4775 4987 7216 2474 3470 6505 1067 4128 1218 4699 6484 511 5230 5936 6094 2002 5526 3774 729 5677 5603 1721 3901 7065 6728 2570 447 3050 1510 1860 932 6877 3866 4537 1621 6619 1818 6099 783 2335 4683 2828 6347 3136 5266 1111 4167 239 4297 5389 338 3314 3820...
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 1ms
memory: 7952kb
input:
100 100 872 43 23 243 80978 417 75079 988 68940 582 1559 373 27729 628 51082 264 93016 190 13782 368 58428 897 80495 301 37679 547 11023 205 92222 624 56637 625 66466 611 3624 94 89164 425 98791 375 74092 36 20946 617 7419 423 93544 512 41513 318 53293 65 68022 596 77868 7 68500 926 73778 623 22432 ...
output:
1409 2464 5403 3113 2142 3750 1566 1118 2114 4794 1603 2925 1210 3533 3699 3335 484 2657 2216 175 3455 2558 2755 1830 395 3332 75 5256 3477 4867 1693 5117 4713 5333 2821 570 1873 719 4656 633 3253 4955 2288 4622 1983 1014 1969 1777 155 954 4430 4053 4472 2946 5280 4346 4190 3018 932 5078 3379 2812 2...
result:
ok 100 numbers
Test #9:
score: 0
Accepted
time: 235ms
memory: 13644kb
input:
100000 100000 1 25704 37 16888245 925079935 308283794 542009300 627584873 995334810 751000987 429683313 459024063 444914461 474450864 797533170 856932888 160575868 964260272 539328827 166046523 693162048 525729509 368284752 839169063 472558166 139776202 49489054 591703001 887967005 984099377 3715712...
output:
16889217 308284363 627585919 751001438 459024530 474451702 856933056 964260839 166047251 525729896 839169559 139776254 591703934 984099767 474963927 32910212 362066460 577817857 453606387 605066446 503470959 435811842 752935681 781230866 30521226 726099463 157684052 247729104 142794465 363882341 979...
result:
ok 100000 numbers
Test #10:
score: 0
Accepted
time: 239ms
memory: 13644kb
input:
100000 100000 1 2275 283 699387118 986932596 808923146 911574961 257315010 836287776 520994268 389524871 245731476 16765585 518330612 278937521 593611730 834638397 104702790 760954814 229606602 269597234 299564282 660983920 20901445 549901323 498811308 72842849 336864687 709615812 661975413 81143752...
output:
699388650 808924561 257316308 520994873 245731502 518331045 593613026 104703971 229607020 299565308 20902299 498811421 336865789 661976673 378620716 561713273 564711747 403936092 461775099 285655480 365333862 545249870 295878396 685479767 429430290 357716488 364324139 252158601 768283030 973833393 9...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 246ms
memory: 13936kb
input:
100000 100000 1 380261 2 186667978 499033859 673157414 678198174 608058496 816615333 252674143 381135262 200918842 969113419 735580817 394953864 997794832 506658413 473835662 942773220 158837716 548808459 981845479 947700186 160237980 998831748 229314272 205378259 414175385 853647072 274300117 37496...
output:
186668634 673158305 608059569 252674644 200920116 735581336 997795498 473836901 158838437 981846725 160239293 229314542 414176507 274300610 39602320 970516117 283059388 777507302 678846261 83621679 851730874 974903910 74776395 299335439 309631911 771537100 837436376 49476536 15026493 224419865 45464...
result:
ok 100000 numbers
Test #12:
score: 0
Accepted
time: 270ms
memory: 13936kb
input:
100000 100000 568114 592199 2 572716839 659655072 781180902 323991960 272010240 927022647 121684018 881935932 419444144 19742236 385055565 179978623 526680137 830446217 606194492 247854552 625607973 983066065 259626607 299889603 760117477 624767358 953892288 607517233 423929548 358862551 485322795 6...
output:
572717394 781181174 272011020 121684760 419444160 385055716 526680836 606194700 625608800 259626859 760118003 953892799 423929850 485323320 987979775 297175050 984924101 356743246 360286176 302962392 495089818 112109334 995912673 592371229 481348301 931151617 757608691 365611112 474823203 589592391 ...
result:
ok 100000 numbers
Test #13:
score: 0
Accepted
time: 284ms
memory: 19964kb
input:
100000 100000 1 871728643 1 822404295 820025713 868947033 149856382 691302080 801725745 303953457 79556803 983829462 252246033 815026919 175186608 422717262 640136463 345851909 205846300 1287268 866848302 458756259 971203158 358410318 870853049 762752207 340007817 426610353 433508028 672976881 94567...
output:
822404295 868947033 691302080 303953457 983829462 815026919 422717262 345851909 1287268 458756260 358410318 762752207 426610353 672976881 728001425 482625430 332756853 897909217 779228695 503260550 20624952 467370446 442947644 124965826 254224843 787978036 495007041 100303320 48130618 848508744 6507...
result:
ok 100000 numbers
Test #14:
score: 0
Accepted
time: 270ms
memory: 20112kb
input:
100000 100000 2 295256 2355 111422705 681565511 398700554 381591710 773165336 859045170 706428133 472112386 495662806 777405909 587399068 695692709 404638925 425029808 178916375 130298075 967298961 520817895 540218949 760467333 668321605 951117052 310336560 155557502 901425123 244067610 528396354 62...
output:
111422705 398700554 773165337 706428133 495662807 587399069 404638925 178916375 967298961 540218950 668321606 310336560 901425123 528396354 857206207 229403507 885767850 53040017 879814961 819970134 208508209 291221298 582826191 843759095 762373475 61936365 733235649 243302941 997620677 844408859 79...
result:
ok 100000 numbers
Test #15:
score: 0
Accepted
time: 273ms
memory: 20116kb
input:
100000 100000 1 49008882 15 373928612 245087533 211270566 152022260 665420727 645324182 286010751 111529891 46129126 962825702 194436554 862160266 771574716 34870123 358706956 419036193 427492266 216553974 170547482 954905785 528718564 341218421 896701638 329010929 422936079 490113977 223472155 2846...
output:
373928612 211270566 665420727 286010751 46129127 194436555 771574716 358706956 427492266 170547483 528718564 896701638 422936079 223472155 86233566 842620703 466695735 452130294 788032340 8290284 979641523 116178863 682270497 903028379 30038957 292302356 884088219 167239089 167592760 963740897 25505...
result:
ok 100000 numbers
Test #16:
score: 0
Accepted
time: 74ms
memory: 18112kb
input:
100000 1 1 586592486 1 1000000000 319101228 1000000000 710134612 1000000000 236764709 1000000000 41028181 1000000000 717973964 1000000000 156457112 1000000000 514472633 1000000000 889344112 1000000000 664372718 1000000000 897845827 1000000000 728764038 1000000000 299997424 1000000000 213653635 10000...
output:
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
result:
ok 100000 numbers
Test #17:
score: 0
Accepted
time: 75ms
memory: 14540kb
input:
100000 1 1 571954189 1 1000000000 692083985 1000000000 362007368 1000000000 961878211 1000000000 618584171 1000000000 313619652 1000000000 35972943 1000000000 912392439 1000000000 910862821 1000000000 411279934 1000000000 566887062 1000000000 309588505 1000000000 724813900 1000000000 66674619 100000...
output:
1000000000 1000000000 1000000001 1000000002 1000000002 1000000000 1000000003 1000000004 1000000004 1000000005 1000000005 1000000006 1000000000 1000000000 1000000007 1000000000 1000000007 1000000000 1000000007 1000000008 1000000009 1000000010 1000000000 1000000010 1000000000 1000000011 1000000000 100...
result:
ok 100000 numbers
Test #18:
score: 0
Accepted
time: 81ms
memory: 15460kb
input:
100000 1 1 877435442 1 1000000000 218892631 1000000000 826470709 1000000000 137395185 1000000000 196665411 1000000000 647692533 1000000000 987990379 1000000000 97227235 1000000000 787816375 1000000000 409661572 1000000000 680069888 1000000000 757986505 1000000000 908912331 1000000000 671615445 10000...
output:
1000000000 1000000000 1000000000 1000000000 1000000000 1000000001 1000000000 1000000002 1000000002 1000000002 1000000002 1000000003 1000000003 1000000004 1000000004 1000000004 1000000000 1000000000 1000000004 1000000004 1000000005 1000000005 1000000006 1000000000 1000000006 1000000007 1000000000 100...
result:
ok 100000 numbers
Test #19:
score: 0
Accepted
time: 70ms
memory: 17316kb
input:
100000 1 1 253258052 1 1000000000 890734295 1000000000 639374351 1000000000 745701403 1000000000 629346697 1000000000 36205124 1000000000 950542 1000000000 846582017 1000000000 879017138 1000000000 669356470 1000000000 482230395 1000000000 703015742 1000000000 990423843 1000000000 373667576 10000000...
output:
1000000001 1000000001 1000000002 1000000002 1000000000 1000000000 1000000003 1000000004 1000000004 1000000000 1000000005 1000000006 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000008 1000000000 1000000009 100...
result:
ok 100000 numbers
Test #20:
score: 0
Accepted
time: 92ms
memory: 12988kb
input:
100000 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
1999999998 2999999997 3999999996 4999999995 5999999994 6999999993 7999999992 8999999991 9999999990 10999999989 11999999988 12999999987 13999999986 14999999985 15999999984 16999999983 17999999982 18999999981 19999999980 20999999979 21999999978 22999999977 23999999976 24999999975 25999999974 269999999...
result:
ok 100000 numbers