QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327625 | #8016. 不休陀螺 | zsq147258369 | 50 | 1976ms | 495704kb | C++14 | 2.3kb | 2024-02-15 11:35:41 | 2024-04-10 01:46:04 |
Judging History
answer
#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+50;
void read(int&x)
{
char c;
while(c=getchar(),c<'0'||c>'9');x=c-'0';
while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';
}
int n,E,a[N],b[N],p[N],ro[N],st[N],top,fir[N],ans,w[N],f[N],tot,g[N],h[N];
bool cmp(int a,int b)
{
return f[a]==f[b]?a<b:f[a]<f[b];
}
int find(int x)
{
return x==ro[x]?x:(ro[x]=find(ro[x]));
}
int val(int x)
{
return E-p[find(x)]+fir[x-1];
}
int ch[N*20][2],v[N*20],siz[N*20],rd[N*20];
class fhq
{
public:
#define ls ch[x][0]
#define rs ch[x][1]
int ro;
inline void up(int x){siz[x]=siz[ls]+siz[rs]+1;}
inline int make_new(int val)
{
int x=++tot;v[x]=val;siz[x]=1;rd[x]=rand();
return x;
}
inline void split(int x,int k,int&a,int&b)
{
if(!x)a=b=0;
else
{
if(v[x]<=k)a=x,split(rs,k,rs,b);
else b=x,split(ls,k,a,ls);
up(x);
}
}
inline int merge(int a,int b)
{
if(!a||!b)return a+b;
if(rd[a]<rd[b])
{
ch[a][1]=merge(ch[a][1],b);
up(a);return a;
}
else
{
ch[b][0]=merge(a,ch[b][0]);
up(b);return b;
}
}
inline void add(int x)
{
int a=0,b=0;
split(ro,x,a,b);int k=make_new(x);
ro=merge(merge(a,k),b);
}
inline int the_rk_of(int x)
{
int a=0,b=0,ans;
split(ro,x-1,a,b);
ans=siz[a];
ro=merge(a,b);
return ans;
}
}t[N];
void insert(int x,int val)
{
for(int i=x;i<=n;i+=(i&(-i)))t[i].add(val);
}
int find(int x,int val)
{
int ans=0;
for(int i=x;i;i-=(i&(-i)))ans+=t[i].the_rk_of(val);
return ans;
}
main()
{
// freopen("in.txt","r",stdin);
// freopen("top.in","r",stdin);
// freopen("top.out","w",stdout);
srand(time(0));
read(n);read(E);
for(int i=1;i<=n;i++)read(a[i]),ro[i]=g[i]=i;
for(int i=1;i<=n;i++)read(b[i]),fir[i]=fir[i-1]+(w[i]=max(0ll,a[i]-b[i])),p[i]=a[i]-w[i],f[i]=f[i-1]+b[i]-a[i];
sort(g,g+1+n,cmp);
for(int i=0;i<=n;i++)h[g[i]]=i+1;
st[++top]=1;insert(n,h[0]);ans+=b[1]>=a[1];
for(int i=2;i<=n;i++)
{
while(top&&p[st[top]]<=p[i])ro[st[top--]]=i;
st[++top]=i;
int l=1,r=i-1,t=i+1;
while(l<=r)
{
int pos=(l+r)>>1;
if(fir[i]<=val(pos))t=pos,r=pos-1;
else l=pos+1;
}
insert(n-i+1,h[i-1]);ans+=find(n-t+1,h[i]);
}
cout<<ans;
}
详细
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 5ms
memory: 24732kb
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: 4ms
memory: 26880kb
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: 4ms
memory: 24804kb
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: 24888kb
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: 1870ms
memory: 388856kb
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: -10
Wrong Answer
time: 1016ms
memory: 495704kb
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:
83332166674
result:
wrong answer 1st lines differ - expected: '83332166680', found: '83332166674'
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 1080ms
memory: 493764kb
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:
99999499996
result:
wrong answer 1st lines differ - expected: '99999500000', found: '99999499996'
Subtask #4:
score: 0
Time Limit Exceeded
Test #14:
score: 10
Accepted
time: 324ms
memory: 104220kb
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:
329807918
result:
ok single line: '329807918'
Test #15:
score: 0
Accepted
time: 861ms
memory: 209676kb
input:
402729 5000 0 1 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 1 0 1 1 0 1 ...
output:
4060615624
result:
ok single line: '4060615624'
Test #16:
score: -10
Time Limit Exceeded
input:
942956 10000 1 0 1 1 1 0 1 0 1 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 1...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #18:
score: 20
Accepted
time: 897ms
memory: 181512kb
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: -20
Time Limit Exceeded
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:
result:
Subtask #6:
score: 30
Accepted
Test #24:
score: 30
Accepted
time: 1115ms
memory: 239224kb
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: 1976ms
memory: 392704kb
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: 798ms
memory: 191672kb
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: 1849ms
memory: 350744kb
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: 0
Accepted
time: 1052ms
memory: 234520kb
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:
125597821
result:
ok single line: '125597821'
Test #29:
score: 0
Accepted
time: 844ms
memory: 187060kb
input:
352598 552392951 477953 72537 92658 281914 179509 124319 138913 46122 123351 156330 385539 397580 280635 230382 210819 255981 389665 48159 303958 241938 337720 81718 194168 168943 464666 258109 295828 163912 385488 110795 194317 92858 212013 74761 360824 92353 234346 256945 26777 112984 145735 47253...
output:
1683912571
result:
ok single line: '1683912571'
Test #30:
score: 0
Accepted
time: 92ms
memory: 69684kb
input:
111704 628642840 13199700 32124349 14698182 24004412 9673344 30567805 9136635 28169543 23827672 33589673 46359443 23996180 43086763 28934606 24514226 35704043 6208097 39610464 20864857 506456 22132660 29798293 43883914 42208348 37316958 5780390 39348069 18672332 7872450 150416 48037426 29816781 1557...
output:
6009983638
result:
ok single line: '6009983638'
Test #31:
score: 0
Accepted
time: 344ms
memory: 188232kb
input:
354793 720027252 40983988 33401041 54567379 52134967 40923834 40282497 42994225 59831114 26162718 18905590 56961601 62454063 49009835 46558527 1159586 39236751 7335945 18017002 14316034 29374227 57791439 40017313 26036290 6883774 46146967 64103491 57564631 70954541 28828703 36466033 37835061 2107130...
output:
17435270706
result:
ok single line: '17435270706'
Test #32:
score: 0
Accepted
time: 283ms
memory: 166604kb
input:
302926 989802465 60020559 11677495 70159984 246480805 13459231 171088896 158477059 127426890 59883990 51253511 145287519 214141415 46450107 92903884 60162590 163860304 40173316 215206023 63409155 163937544 185626997 4423095 207789551 7817602 33103460 67077590 170529891 33157362 159606226 112756694 3...
output:
9322548233
result:
ok single line: '9322548233'