QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#324072 | #8016. 不休陀螺 | lgvc | 50 | 321ms | 113300kb | C++14 | 1.5kb | 2024-02-10 15:41:56 | 2024-02-10 15:41:57 |
Judging History
answer
#include <bits/stdc++.h>
long long qb[1000009],s3[1000009];
int N,E,a[1000009],tk,b[1000009],st[1000009][20],sl[1000009],sg[1000009];
int qm(int l,int r) {
return std::max(st[l][sl[r-l+1]],st[r-(1<<sl[r-l+1])+1][sl[r-l+1]]);
}
#define lb(n) ((n)&(-(n)))
void up(int n,int v) {
while(n<=tk+1) {
sg[n]+=v;
n+=lb(n);
}
}
int qr(int n) {
int as=0;
while(n) {
as+=sg[n];
n-=lb(n);
}
return as;
}
signed main(void) {
scanf("%d %d",&N,&E);
for(int i=1;i<=N;i++) {
scanf("%d",&a[i]);
}
for(int i=1;i<=N;i++) {
scanf("%d",&b[i]);
st[i][0]=std::min(a[i],b[i]);
s3[i]=s3[i-1]+a[i]-b[i];
qb[i]=s3[i];
}
std::sort(qb,qb+N+1);
tk=std::unique(qb,qb+N+1)-qb;
for(int i=0;i<=N;i++) {
s3[i]=std::lower_bound(qb,qb+tk+1,s3[i])-qb+1;
}
for(int i=2;i<=N;i++) sl[i]=sl[i>>1]+1;
for(int i=1;i<=19;i++) {
for(int j=1;j<=N;j++) {
st[j][i]=std::max(st[j][i-1],st[j+(1<<i-1)][i-1]);
}
}
/* long long ans2=0;
for(int i=1;i<=N;i++) {
long long s1=0,s2=0,s3=0;
for(int j=i;j+(1<<i)-1<=N;j++) {
s1+=std::max(a[j]-b[j],0);
s2=std::max(s2,1ll*std::min(a[j],b[j]));
s3+=a[j]-b[j];
if(s1+s2<=E&&s3<=0) ans2++;
}
}
printf("%lld\n",ans2);*/
int q=0;
long long s1=0,ans=0;
for(int i=1;i<=N;i++) {
if(q<i) q=i-1;
while(q<N) {
if(s1+std::max(a[q+1]-b[q+1],0)+qm(i,q+1)<=E) {
q++;
s1+=std::max(a[q]-b[q],0);
up(s3[q],1);
} else break;
}
ans+=qr(s3[i-1]);
if(q>=i) s1-=std::max(a[i]-b[i],0),up(s3[i],-1);
}
printf("%lld",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 4ms
memory: 16160kb
input:
5000 939255322 47952340 92329911 61615795 40122788 47258178 29326499 9822850 42767362 86610596 60318756 52429688 87502511 50194916 96377063 74322128 19511341 28794957 53813791 79075058 35555414 5249682 45174421 101856091 25257909 94697470 45853817 82945426 108415825 41731145 87133877 75167193 598696...
output:
1846283
result:
ok single line: '1846283'
Test #2:
score: 0
Accepted
time: 3ms
memory: 14200kb
input:
4329 694688892 165277824 152780705 114369871 103975989 100188012 147665514 101173335 39350309 37624153 95413467 157561608 10779445 35486823 19200231 55106545 50853515 35799174 92799915 152580135 158388210 132197954 75468895 66543749 104662491 59493152 108170563 22295314 152619070 77921052 105881528 ...
output:
889705
result:
ok single line: '889705'
Test #3:
score: 0
Accepted
time: 0ms
memory: 14208kb
input:
4932 10000000 879202 367773 895593 794951 253764 695611 164309 502290 638542 960084 766095 457948 783698 475707 157847 491793 196608 378324 211974 924944 42162 797172 334660 900879 522660 328814 402169 938267 498991 347773 922727 827106 16528 994043 12381 756925 642283 186848 423956 927655 344750 14...
output:
10724274
result:
ok single line: '10724274'
Test #4:
score: 0
Accepted
time: 3ms
memory: 14244kb
input:
4545 10000000 343712 838600 973396 360269 315252 660011 857231 837695 934030 232383 174532 293701 238344 367417 96713 556096 316705 468048 511763 208940 360904 853055 809137 119764 388946 415546 420603 893876 816501 899208 82913 705704 70043 223366 792251 899049 782406 849921 967761 54994 105919 384...
output:
5542899
result:
ok single line: '5542899'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 10
Accepted
time: 282ms
memory: 97260kb
input:
774484 763692678 47702350 34856775 28447988 4178162 45063720 8232662 36845607 27038945 44858289 5952529 39159657 21628528 60199611 5544054 59216841 39287087 43449994 20034684 56440004 11583811 44465341 32347476 49196492 22731571 9481143 11726859 35167370 23103544 23109378 38822668 29778048 58004104 ...
output:
124023429
result:
ok single line: '124023429'
Test #6:
score: 0
Accepted
time: 238ms
memory: 109320kb
input:
1000000 1145141 41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 491 2995 11942 4827 5436 32391 14604 3902 153 292 12382 17421 18716 19718 19895 5447 21726 14771 11538 1869 19912 25667 26299 17035 9894 28703 23811 31322 30333 17673 4664 15141 7711 28253 6868 25547 ...
output:
83332166680
result:
ok single line: '83332166680'
Test #7:
score: -10
Wrong Answer
time: 231ms
memory: 109332kb
input:
992939 818293947 41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 491 2995 11942 4827 5436 32391 14604 3902 153 292 12382 17421 18716 19718 19895 5447 21726 14771 11538 1869 19912 25667 26299 17035 9894 28703 23811 31322 30333 17673 4664 15141 7711 28253 6868 25547...
output:
92429805789
result:
wrong answer 1st lines differ - expected: '123239741050', found: '92429805789'
Subtask #3:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 294ms
memory: 113300kb
input:
1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
99999500000
result:
ok single line: '99999500000'
Test #11:
score: 0
Accepted
time: 228ms
memory: 101600kb
input:
829382 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
68786703753
result:
ok single line: '68786703753'
Test #12:
score: 0
Accepted
time: 193ms
memory: 92772kb
input:
715382 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
51176496753
result:
ok single line: '51176496753'
Test #13:
score: 0
Accepted
time: 55ms
memory: 34176kb
input:
212234 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
4504051185
result:
ok single line: '4504051185'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 39ms
memory: 39128kb
input:
174457 888 0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1...
output:
329807897
result:
wrong answer 1st lines differ - expected: '329807918', found: '329807897'
Subtask #5:
score: 20
Accepted
Test #18:
score: 20
Accepted
time: 130ms
memory: 53332kb
input:
343922 773619774 0 8292680 5684115 0 0 170056 5385926 0 0 1588575 0 0 10947891 170867 35145 0 0 103085 7231562 0 0 0 0 11128944 0 4872226 0 2879880 7565181 0 8631665 0 5162564 9511835 514165 0 9628987 14357934 174784 0 12400154 0 0 8198218 0 8496060 0 0 0 0 10376826 3523227 0 14548249 0 6840016 0 0 ...
output:
36107528
result:
ok single line: '36107528'
Test #19:
score: 0
Accepted
time: 321ms
memory: 98864kb
input:
822037 644760584 0 2469002 0 5619339 0 0 0 41690 0 2840922 7972819 2323916 0 7218270 0 0 6647344 1095198 0 5412830 6654778 0 4588035 0 5181193 5073101 0 0 0 2371931 2740725 6756043 4534813 1080318 3180435 0 0 0 7537979 0 9432571 3034547 1737404 7266942 0 0 5894473 2658989 0 3648760 6086440 768115 16...
output:
117551199
result:
ok single line: '117551199'
Test #20:
score: 0
Accepted
time: 112ms
memory: 52940kb
input:
318889 580944500 0 53440448 62414510 4444108 16412385 37171101 0 0 65074099 0 0 0 0 0 0 1736666 40422852 25240303 0 0 48581689 0 51050599 0 25918077 0 1579933 0 0 6387116 64336506 0 0 21191911 1157620 0 63412896 28547264 15735514 28842299 56755053 1569652 18413574 0 0 38907260 13487516 3629386 0 0 3...
output:
6426676
result:
ok single line: '6426676'
Test #21:
score: 0
Accepted
time: 235ms
memory: 85456kb
input:
634480 869644773 24926780 0 0 5806548 29345967 0 0 24585164 5082228 0 36723829 0 45565685 38830813 40656683 0 43901325 0 0 24818007 0 9578233 0 29516514 0 45637396 0 17904712 3102583 29421661 0 17144626 0 26616707 20864851 30084372 0 13288472 33594305 10029647 27932498 0 37897745 5476038 0 0 0 0 0 0...
output:
24380270
result:
ok single line: '24380270'
Test #22:
score: 0
Accepted
time: 85ms
memory: 51608kb
input:
343922 773619774 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8425454 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11326 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
1735552293
result:
ok single line: '1735552293'
Test #23:
score: 0
Accepted
time: 247ms
memory: 101628kb
input:
822037 644760584 0 0 0 0 0 3279389 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3763535 0 0 0 0 0 0 0 3461349 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
5718720820
result:
ok single line: '5718720820'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 30
Accepted
time: 153ms
memory: 68420kb
input:
468676 582048177 6889433 7293342 20676061 15545414 4911497 12352219 8921719 1705801 19695926 25259227 2645394 17518171 19753552 9449377 982708 22479531 1267985 15594372 20685422 9627290 2017543 6459134 18614020 16206301 14962487 12932255 7101003 29140540 6479702 20607124 2540287 15565156 20274141 11...
output:
353280708
result:
ok single line: '353280708'
Test #25:
score: 0
Accepted
time: 302ms
memory: 95292kb
input:
784267 870748450 16640230 34729067 17389326 19816959 33620307 37478599 33913657 25049965 6902010 9380232 7310329 20289065 20894948 36698878 14442257 16359540 28719955 22890081 28478376 3754189 32959471 19507131 24813668 42236708 1945451 16082602 30349832 14901697 28954054 11411772 23608962 31549506 ...
output:
480109294
result:
ok single line: '480109294'
Test #26:
score: 0
Accepted
time: 119ms
memory: 56360kb
input:
362381 806932367 1998992 1594953 1725217 2857016 1122874 2090929 2993571 191305 1573025 2672535 1939866 1432142 1806544 3370274 2180549 2081497 1432017 1957729 207320 2085266 1921419 2009336 1907065 1910662 884271 1887072 1433721 3466028 1976853 1568106 2373768 1562497 1146486 3357210 2143242 199440...
output:
320147189
result:
ok single line: '320147189'
Test #27:
score: 0
Accepted
time: 243ms
memory: 88928kb
input:
677972 743116283 14654866 19965629 33134497 22424942 33594556 8114856 25149702 29975590 31342994 58022893 40342918 20932203 15146022 8605338 55089456 49856121 2941066 53849623 19246055 48804704 3173058 41957054 29981415 16838091 44168911 44677532 53105164 48358902 34377645 4249146 29400964 7246055 5...
output:
306770227
result:
ok single line: '306770227'
Test #28:
score: -30
Wrong Answer
time: 172ms
memory: 68348kb
input:
458893 827508762 36663011 92223323 106548542 647324 99037913 47547432 137915431 54505622 69541989 10691843 113932708 25432404 67685209 28957701 44393252 90019267 58951381 15237406 47038891 61220493 82165280 115267421 130633521 124357788 131281807 48792405 148921282 137582798 105812001 100693484 1484...
output:
125597820
result:
wrong answer 1st lines differ - expected: '125597821', found: '125597820'