QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#132415 | #3857. Single-track railway | adwsaef | WA | 0ms | 4560kb | C++17 | 1.3kb | 2023-07-29 20:37:05 | 2023-07-29 20:37:09 |
Judging History
answer
#include <iostream>
constexpr int SIZE=524288, max_N=200001;
int tree[SIZE];
int t[max_N];
void update (int x){
while (x!=0){
tree[x]=tree[2*x]+tree[2*x+1];
x/=2;
}
}
int result (int station, int s, int pref){
int o1=pref;
int o2=s-o1;
return s-2*std::min(o1,o2);
}
int solve (int s){
int cr=1;
int taken=0;
while (cr<SIZE/2){
if ((taken+tree[cr*2])*2<=s){
taken+=tree[cr*2];
cr=cr*2+1;
}else{
cr*=2;
}
}
int station=cr-SIZE/2;
return std::min(result(station,s,taken),result(station+1,s,taken+tree[cr]));
}
int main(){
std::ios_base::sync_with_stdio(false);
std::cout.tie(0);
std::cout.tie(0);
int n;
std::cin>>n;
int s=0;
for (int i=1; i<n; ++i){
std::cin>>t[i];
t[i]*=2;
tree[SIZE/2+i-1]=t[i];
s+=t[i];
}
for (int i=SIZE/2-1; i>=1; --i)tree[i]=tree[2*i]+tree[2*i+1];
std::cout<<solve(s)<<'\n';
int k;
std::cin>>k;
int a, b;
for (int i=0; i<k; ++i){
std::cin>>a>>b;
b*=2;
tree[SIZE/2+a-1]=b;
update((SIZE/2+a-1)/2);
s+=b-t[a];
t[a]=b;
std::cout<<solve(s)/2<<'\n';
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4560kb
input:
2 39 7 1 20 1 70 1 56 1 37 1 37 1 37 1 91
output:
78 20 70 56 37 37 37 91
result:
wrong answer 1st lines differ - expected: '39', found: '78'