QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327660 | #8016. 不休陀螺 | 2745518585 | 10 | 479ms | 76808kb | C++14 | 2.2kb | 2024-02-15 11:47:05 | 2024-02-15 11:47:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline char gc()
{
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
template<typename T> inline void read(T &x)
{
T u=1,t=0;char c=gc();
while(c<'0'||c>'9') {if(c=='-') u=-1; c=gc();}
while(c>='0'&&c<='9') t*=10,t+=c-'0',c=gc();
x=u*t;return;
}
template<typename T,typename ...O> inline void read(T &x,O &...o) {read(x),read(o...);}
const int N=1000001;
int n,k,a[N],b[N],d[N];
ll f[N],g[N],h[N];
namespace sgt1
{
struct tree
{
int l,r;
ll s;
}T[N<<2];
void pushup(int x)
{
T[x].s=max(T[x<<1].s,T[x<<1|1].s);
}
void build(int x,int l,int r)
{
T[x].l=l,T[x].r=r;
if(l==r)
{
T[x].s=a[l]-max(a[l]-b[l],0);
return;
}
int z=l+r>>1;
build(x<<1,l,z);
build(x<<1|1,z+1,r);
pushup(x);
}
ll sum(int x,int l,int r)
{
if(T[x].l>=l&&T[x].r<=r)
{
return T[x].s;
}
int z=T[x].l+T[x].r>>1;
ll s=-1e18;
if(l<=z) s=max(s,sum(x<<1,l,r));
if(r>z) s=max(s,sum(x<<1|1,l,r));
return s;
}
}
namespace sgt2
{
int T[N];
void add(int x,int k)
{
while(x<=n) T[x]+=k,x+=x&-x;
}
int sum(int x)
{
int s=0;
while(x>=1) s+=T[x],x-=x&-x;
return s;
}
}
bool check(int l,int r)
{
return k-(f[r]-f[l-1])>=sgt1::sum(1,l,r);
}
int main()
{
read(n),read(k);
for(int i=1;i<=n;++i) read(a[i]);
for(int i=1;i<=n;++i) read(b[i]);
sgt1::build(1,1,n);
for(int i=1;i<=n;++i)
{
f[i]=f[i-1]+max(a[i]-b[i],0);
g[i]=g[i-1]+(b[i]-a[i]);
h[i]=g[i];
}
sort(h+1,h+n+1);
for(int i=1;i<=n;++i)
{
d[i]=lower_bound(h+1,h+n+1,g[i])-h;
}
int x=0;
ll s=0;
for(int i=1;i<=n;++i)
{
if(x<i) x=i-1;
while(x+1<=n&&check(i,x+1)) sgt2::add(n-d[++x]+1,1);
s+=sgt2::sum(n-d[i-1]+1);
if(x>=i) sgt2::add(n-d[i]+1,-1);
}
printf("%lld",s);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 14392kb
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:
1846969
result:
wrong answer 1st lines differ - expected: '1846283', found: '1846969'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 405ms
memory: 76468kb
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:
124023511
result:
wrong answer 1st lines differ - expected: '124023429', found: '124023511'
Subtask #3:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 479ms
memory: 76808kb
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: 402ms
memory: 76744kb
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: 330ms
memory: 73844kb
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: 91ms
memory: 33060kb
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: 67ms
memory: 33724kb
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:
329809333
result:
wrong answer 1st lines differ - expected: '329807918', found: '329809333'
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 160ms
memory: 42656kb
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:
36107607
result:
wrong answer 1st lines differ - expected: '36107528', found: '36107607'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 234ms
memory: 50316kb
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:
353281146
result:
wrong answer 1st lines differ - expected: '353280708', found: '353281146'