QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187002 | #3857. Single-track railway | Nax_hueux# | WA | 1ms | 5812kb | C++14 | 1.6kb | 2023-09-24 13:51:52 | 2023-09-24 13:51:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int re_ad(){
int x=0,f=0; char c=getchar();
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=x*10+(c^'0'),c=getchar();
return f?-x:x;
}
int n,k;
int a[200100];
long long t[800010],sum;
inline void pushup(int k)
{
t[k]=t[k<<1]+t[k<<1|1];
}
void build(int k,int l,int r)
{
if(l==r){t[k]=a[l];return;}
int mid=(l+r)>>1;
build(k<<1,l,mid);build(k<<1|1,mid+1,r);
pushup(k);
}
void change(int k,int l,int r,int pos)
{
if(l==r){t[k]=a[l];return;}
int mid=(l+r)>>1;
if(pos<=mid)change(k<<1,l,mid,pos);
else change(k<<1|1,mid+1,r,pos);
pushup(k);
}
int find(int k,int l,int r,long long num)
{
if(l==r)return l;
int mid=(l+r)>>1;
if(t[k<<1]>=num){return find(k<<1,l,mid,num);}
else return find(k<<1|1,mid+1,r,num-t[k<<1|1]);
}
long long query(int k,int l,int r,int pos)
{
if(r<=pos)return t[k];
int mid=(l+r)>>1;
if(pos<=mid)return query(k<<1,l,mid,pos);
else return t[k<<1]+query(k<<1|1,mid+1,r,pos);
}
int main()
{
int i,j;
long long an;
n=re_ad();
for(i=1;i<n;++i)
{
a[i]=re_ad();sum+=a[i];
}
build(1,1,n-1);
j=find(1,1,n-1,sum/2);
an=abs(2ll*query(1,1,n-1,j)-sum);
for(int l=max(j-1,1);l<=min(j+1,n-1);++l)if(l!=j)
{
an=min(an,abs(2ll*query(1,1,n-1,l)-sum));
}
printf("%lld\n",an);
k=re_ad();
while(k--)
{
i=re_ad();j=re_ad();
sum-=a[i];sum+=j;a[i]=j;
change(1,1,n-1,i);
j=find(1,1,n-1,sum/2);
an=abs(2ll*query(1,1,n-1,j)-sum);
for(int l=max(j-1,1);l<=min(j+1,n-1);++l)if(l!=j)
{
an=min(an,abs(2ll*query(1,1,n-1,l)-sum));
}
printf("%lld\n",an);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5812kb
input:
2 39 7 1 20 1 70 1 56 1 37 1 37 1 37 1 91
output:
39 20 70 56 37 37 37 91
result:
ok 8 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
3 8 41 0
output:
33
result:
ok single line: '33'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3836kb
input:
30 86 100 80 30 23 17 90 98 20 3 43 31 49 14 14 47 13 44 7 30 50 29 67 68 56 69 28 61 81 10 21 23 7 99 16 70 3 50 4 17 26 42 7 37 10 43 26 83 13 96
output:
20 47 56 33 3 10 17 17 5 18 1
result:
wrong answer 1st lines differ - expected: '8', found: '20'