Submission #486912

#TimeUsernameProblemLanguageResultExecution timeMemory
486912Urvuk3Sterilizing Spray (JOI15_sterilizing)C++17
100 / 100
283 ms9744 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MAXN=1e6,MAXA=5e6+5,INF=1e9,LINF=1e18; #define fi first #define se second #define pll pair<ll,ll> #define pii pair<int,int> #define mid (l+r)/2 #define sz(a) int((a).size()) #define all(a) a.begin(),a.end() #define mod 1000000007LL #define pb push_back #define endl "\n" #define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush; #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pb push_back #define pf push_front #define ppf pop_front #define ppb pop_back #define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; } ll n,m,k,q,x,y,z,res=0,l,r; string s,t; vector<int> a; ifstream input; ofstream output; #ifdef ONLINE_JUDGE #define input cin #define output cout #endif struct cvor{ ll sm,mx,mn; }; cvor seg[4*MAXN]; void init(int node,int l,int r){ if(l==r){ seg[node].sm=a[l]; seg[node].mx=a[l]; seg[node].mn=a[l]; return; } init(2*node,l,mid); init(2*node+1,mid+1,r); seg[node].sm=seg[2*node].sm+seg[2*node+1].sm; seg[node].mx=max(seg[2*node].mx,seg[2*node+1].mx); seg[node].mn=min(seg[2*node].mn,seg[2*node+1].mn); } void update(int node,int l,int r,int idx,int val){ if(l==r){ seg[node].sm=val; seg[node].mx=val; seg[node].mn=val; return; } if(idx<=mid) update(2*node,l,mid,idx,val); else update(2*node+1,mid+1,r,idx,val); seg[node].sm=seg[2*node].sm+seg[2*node+1].sm; seg[node].mx=max(seg[2*node].mx,seg[2*node+1].mx); seg[node].mn=min(seg[2*node].mn,seg[2*node+1].mn); } void spray(int node,int l,int r,int L,int R){ if(l>r || l>R || r<L || (seg[node].mx==0 && seg[node].mn==0)) return; if(l==r){ int nov=seg[node].sm/k; seg[node].sm=nov; seg[node].mx=nov; seg[node].mn=nov; return; } spray(2*node,l,mid,L,R); spray(2*node+1,mid+1,r,L,R); seg[node].sm=seg[2*node].sm+seg[2*node+1].sm; seg[node].mx=max(seg[2*node].mx,seg[2*node+1].mx); seg[node].mn=min(seg[2*node].mn,seg[2*node+1].mn); } ll query(int node,int l,int r,int L,int R){ if(L<=l && r<=R) return seg[node].sm; ll ret=0; if(L<=mid) ret+=query(2*node,l,mid,L,R); if(R>mid) ret+=query(2*node+1,mid+1,r,L,R); return ret; } void solve(){ cin>>n>>q>>k; a.resize(n+1); for(int i=1;i<=n;i++) cin>>a[i]; init(1,1,n); while(q--){ int type; cin>>type; if(type==1){ int a,b; cin>>a>>b; update(1,1,n,a,b); } else if(type==2){ cin>>l>>r; if(k==1) continue; spray(1,1,n,l,r); } else{ cin>>l>>r; cout<<query(1,1,n,l,r)<<endl; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE input.open("D:\\UROS\\Programiranje\\input.in",ios::in); output.open("D:\\UROS\\Programiranje\\output.out",ios::out|ios::trunc); #endif //freopen(".in","r",stdin); //freopen(".out","w",stdout); int t; //cin>>t; t=1; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...