제출 #894628

#제출 시각아이디문제언어결과실행 시간메모리
894628IWKRSterilizing Spray (JOI15_sterilizing)C++17
100 / 100
292 ms16048 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...