This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int s,m,e,v=0;
node *l, *r;
node(int S, int E){
e=E,s=S,m=(s+e)>>1;
if (s!=e) {
l=new node(s,m);
r=new node(m+1,e);
}
}
void add(int S, int E, int V){
if(v==0){return;}
if(s==e){v/=V;return;}
if(E<=m)l->add(S,E,V);
else if(S>m)r->add(S,E,V);
else{
l->add(S,m,V);
r-> add(m+1,E,V);
}
v=l->v+r->v;
}
void update(int X, int V) {
if(s==e){
v=V;
}else{
if(X<=m){
l->update(X,V);
}else{
r->update(X,V);
}
v=l->v+r->v;
}
}
int sum(int S, int E){
if(s==S&&e==E)return v;
if(E<=m)return l->sum(S,E);
else if(S>m)return r->sum(S,E);
else return (l->sum(S,m)) + (r->sum(m+1,E));
}
} *root;
int t,a,b,n,q,k;
signed main(){
cin>>n>>q>>k;
root=new node(0,n-1);
for(int i=0;i<n;i++) {
cin>>a;
root->update(i,a);
}
while(q--){
cin>>t>>a>>b;
a--;
b--;
if(t==2){
if(k==1)continue;
root->add(a,b,k);
}else if(t==3){
cout<<root->sum(a,b)<<'\n';
}else{
b++;
root->update(a,b);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |