Submission #31832

#TimeUsernameProblemLanguageResultExecution timeMemory
31832KanvieSterilizing Spray (JOI15_sterilizing)C++14
5 / 100
5000 ms5920 KiB
#include<bits/stdc++.h> using namespace std; int n,kk,q,x,y,z; long long f[400001],a[100001]; void init(int k, int l, int r) { if(r<l)return; if(l==r) { f[k]=a[l]; return; } int mid=(l+r)/2; init(2*k,l,mid); init(2*k+1,mid+1,r); f[k]=f[2*k]+f[2*k+1]; } void upd(int k, int l, int r, int p, int gt) { if(p<l||p>r||l>r)return; if(l==r) { f[k]=gt; return; } int mid=(l+r)/2; upd(2*k,l,mid,p,gt); upd(2*k+1,mid+1,r,p,gt); f[k]=f[2*k]+f[2*k+1]; } void chg(int k, int l, int r, int L, int R) { if(R<l||L>r||l>r)return; if(l==r) { f[k]/=kk; return; } int mid=(l+r)/2; chg(2*k,l,mid,L,R); chg(2*k+1,mid+1,r,L,R); f[k]=f[2*k]+f[2*k+1]; } long long gets(int k, int l, int r, int L, int R) { if(R<l||L>r||l>r)return 0; if(L<=l&&r<=R)return f[k]; int mid=(l+r)/2; return gets(2*k,l,mid,L,R)+gets(2*k+1,mid+1,r,L,R); } int main() { cin>>n>>q>>kk; for(int i=1;i<=n;++i) { cin>>a[i]; } init(1,1,n); while(q--) { cin>>x>>y>>z; if(x==1) upd(1,1,n,y,z); else { if(x==2) chg(1,1,n,y,z); else cout<<gets(1,1,n,y,z)<<"\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...