QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#186979 | #3857. Single-track railway | gugugu# | WA | 0ms | 3840kb | C++14 | 940b | 2023-09-24 13:39:33 | 2023-09-24 13:39:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=200100;
int a[maxn],n,k;
long long c[maxn];
inline void add(int x,int v) {
for(;x<maxn;x+=(x&(-x))) c[x]+=v;
}
long long sumall;
inline long long query(int x) {
long long ans=0;
for(;x;x&=x-1) ans+=c[x];
return ans;
}
inline int getpos() {
int p=0;
long long s=0;
for(int i=18;i>=0;i--) if(p+(1<<i)<maxn&&(s+c[p+(1<<i)])*2<=sumall) {
p+=(1<<i);
s+=c[p];
}
return p;
}
inline long long getans() {
int p=getpos();
long long sa=query(p),sb=sumall-query(p);
long long ans=sb-sa;
sa=query(p+1);sb=sumall-query(p+1);
ans=min(ans,sa-sb);
return ans;
}
int main() {
scanf("%d",&n);
for(int i=1;i<n;i++) scanf("%d",a+i),add(i,a[i]),sumall+=a[i];
scanf("%d",&k);
printf("%lld\n",getans());
while(k--) {
int pos,v;scanf("%d%d",&pos,&v);
add(pos,v-a[pos]);
sumall+=v-a[pos];
printf("%lld\n",getans());
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3840kb
input:
2 39 7 1 20 1 70 1 56 1 37 1 37 1 37 1 91
output:
39 20 51 68 66 64 62 114
result:
wrong answer 3rd lines differ - expected: '70', found: '51'