QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287640 | #3857. Single-track railway | LaStataleBlue# | WA | 2ms | 22364kb | C++23 | 1.6kb | 2023-12-20 21:01:19 | 2023-12-20 21:01:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define _mid (_l+_r)/2
struct SegmentTree{
long long sum=0;
SegmentTree *left,*right;
static SegmentTree *newSeg(int _l,int _r);
void update(int pos,long long val,int _l,int _r){
if(pos<_l || pos>_r)return;
if(_l==_r){
sum=val;
return;
}
left->update(pos,val,_l,_mid);
right->update(pos,val,_mid+1,_r);
sum=left->sum+right->sum;
}
pair<int,long long> query(long long x,int _l,int _r){
assert(sum>x);
if(_l==_r){
return {_l,x};
}
if(left->sum > x)return left->query(x,_l,_mid);
else return right->query(x-left->sum,_mid+1,_r);
}
};
const int MAXN = 200'005;
SegmentTree vett[MAXN*4];
int cc=0;
SegmentTree* SegmentTree::newSeg(int _l,int _r){
int ind=cc++;
vett[ind].sum=0;
if(_l!=_r){
vett[ind].left = newSeg(_l,_mid);
vett[ind].right = newSeg(_mid+1,_r);
}
return &vett[ind];
}
#undef _mid
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n;
SegmentTree *ds = SegmentTree::newSeg(1,n-1);
vector<long long> v(n);
long long sum=0;
for(int i=1;i<=n-1;i++){
cin>>v[i];
ds->update(i,2*v[i],1,n-1);
sum+=v[i];
}
auto query = [&]()->void{
auto res = ds->query(sum,1,n-1);
if(res.second==0)cout<<"0\n";
else{
cout<<min(res.second,v[res.first]-res.second)<<"\n";
}
};
query();
cin>>k;
for(int i=0;i<k;i++){
int pos;
long long x;
cin>>pos>>x;
sum-=v[pos];
v[pos]=x;
ds->update(pos,2*x,1,n-1);
sum+=v[pos];
query();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 22364kb
input:
2 39 7 1 20 1 70 1 56 1 37 1 37 1 37 1 91
output:
0 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '39', found: '0'