QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327613 | #8016. 不休陀螺 | zsq147258369 | 20 | 1831ms | 291608kb | C++14 | 1.8kb | 2024-02-15 11:26:09 | 2024-02-15 11:26:09 |
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],t[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 tl[N<<2],tr[N<<2],sum[N<<2];
#define ls tl[x]
#define rs tr[x]
#define mid ((l+r)>>1)
#define LS ls,l,mid
#define RS rs,mid+1,r
void insert(int&x,int l,int r,int d)
{
if(!x)x=++tot;++sum[x];
if(l==r)return;
if(d<=mid)insert(LS,d);
else insert(RS,d);
}
int find(int x,int l,int r,int d)
{
if(!x)return 0;
if(d>=r)return sum[x];
if(d<=mid)return find(LS,d);
return find(LS,d)+find(RS,d);
}
void insert(int x,int val)
{
for(int i=x;i<=n;i+=(i&(-i)))insert(t[i],1,n+1,val);
}
int find(int x,int val)
{
int ans=0;
for(int i=x;i;i-=(i&(-i)))ans+=find(t[i],1,n+1,val);
return ans;
}
main()
{
// freopen("in.txt","r",stdin);
// freopen("top.in","r",stdin);
// freopen("top.out","w",stdout);
read(n);read(E);
for(int i=1;i<=n;i++)read(a[i]),ro[i]=t[i]=g[i]=i;tot=n;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 28400kb
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: 24816kb
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: 7ms
memory: 23980kb
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: 24952kb
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: 0
Wrong Answer
time: 1831ms
memory: 280780kb
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:
35795715292068
result:
wrong answer 1st lines differ - expected: '124023429', found: '35795715292068'
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 1192ms
memory: 291608kb
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:
15000175849916
result:
wrong answer 1st lines differ - expected: '99999500000', found: '15000175849916'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 10
Accepted
time: 148ms
memory: 207212kb
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: -10
Wrong Answer
time: 497ms
memory: 247488kb
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:
5623819173609
result:
wrong answer 1st lines differ - expected: '4060615624', found: '5623819173609'
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 570ms
memory: 245724kb
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:
6288200430632
result:
wrong answer 1st lines differ - expected: '36107528', found: '6288200430632'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 729ms
memory: 257380kb
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:
11799688144403
result:
wrong answer 1st lines differ - expected: '353280708', found: '11799688144403'