Submission #739765

#TimeUsernameProblemLanguageResultExecution timeMemory
739765bgnbvnbvSterilizing Spray (JOI15_sterilizing)C++14
100 / 100
243 ms8140 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<int,int> #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=long long; const ll maxN=2e5; const ll inf=1e18; const ll mod=1e9+7; ll st[4*maxN],mx[4*maxN],n; void update(ll pos,ll val,ll id=1,ll l=1,ll r=n) { if(l==r) { st[id]=val; mx[id]=val; return; } ll mid=l+r>>1; if(pos<=mid) update(pos,val,id*2,l,mid); else update(pos,val,id*2+1,mid+1,r); st[id]=st[id*2]+st[id*2+1]; mx[id]=max(mx[id*2],mx[id*2+1]); } ll k; void upd(ll i,ll j,ll id=1,ll l=1,ll r=n) { if(j<l||r<i) return; if(mx[id]==0) return; if(l==r) { st[id]=st[id]/k; mx[id]=mx[id]/k; return; } ll mid=l+r>>1; upd(i,j,id*2,l,mid); upd(i,j,id*2+1,mid+1,r); st[id]=st[id*2]+st[id*2+1]; mx[id]=max(mx[id*2],mx[id*2+1]); } ll get(ll i,ll j,ll id=1,ll l=1,ll r=n) { if(j<l||r<i) return 0; if(i<=l&&r<=j) return st[id]; ll mid=l+r>>1; return get(i,j,id*2,l,mid)+get(i,j,id*2+1,mid+1,r); } ll q,a[maxN]; void solve() { cin >> n >> q >> k; for(int i=1;i<=n;i++) cin >> a[i],update(i,a[i]); for(int i=1;i<=q;i++) { ll t; cin >> t; if(t==1) { ll pos,val; cin >> pos >> val; update(pos,val); } else if(t==2) { ll l,r; cin >> l >> r; if(k!=1) { upd(l,r); } } else { ll l,r; cin >> l >> r; cout << get(l,r)<<'\n'; } } } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

Compilation message (stderr)

sterilizing.cpp: In function 'void update(ll, ll, ll, ll, ll)':
sterilizing.cpp:22:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     ll mid=l+r>>1;
      |            ~^~
sterilizing.cpp: In function 'void upd(ll, ll, ll, ll, ll)':
sterilizing.cpp:39:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |     ll mid=l+r>>1;
      |            ~^~
sterilizing.cpp: In function 'll get(ll, ll, ll, ll, ll)':
sterilizing.cpp:49:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     ll mid=l+r>>1;
      |            ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...