Submission #1158175

#TimeUsernameProblemLanguageResultExecution timeMemory
1158175dostsSterilizing Spray (JOI15_sterilizing)C++20
100 / 100
106 ms4880 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>

const int inf = 2e18,N = 5e5+1,MOD =  1e9+7;


struct ST {
    vi t;

    ST(int nn) {
        t.assign(4*nn+1,0);
    }

    void update(int node,int l,int r,int p,int v) {
        if (l == r) {
            t[node] = v;
            return;
        }
        int m = (l+r) >> 1;
        if (p <= m) update(2*node,l,m,p,v);
        else update(2*node+1,m+1,r,p,v);
        t[node] = t[2*node]+t[2*node+1];
    }

    void spray(int node,int l,int r,int L,int R,int x) {
        if (l > R || r < L) return;
        if (x == 1) return;
        if (!t[node]) return;
        if (l == r) {
            t[node] /= x;
            return;
        }
        int m = (l+r) >> 1;
        spray(2*node,l,m,L,R,x);
        spray(2*node+1,m+1,r,L,R,x);
        t[node] = t[2*node]+t[2*node+1];
    }

    int query(int node,int l,int r,int L,int R) {
        if (l > R || r < L) return 0;
        if (l >= L && r <= R) return t[node];
        int m = (l+r) >> 1;
        return query(2*node,l,m,L,R)+query(2*node+1,m+1,r,L,R);
    }
};

void solve() {
    int n,q,k;
    cin >> n >> q >> k;
    vi a(n+1);
    ST st(n);
    for (int i=1;i<=n;i++) {
        cin >> a[i];
        st.update(1,1,n,i,a[i]);
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int p,v;
            cin >> p >> v;
            st.update(1,1,n,p,v);
        }
        else if (type == 2) {
            int l,r;
            cin >> l >> r;
            st.spray(1,1,n,l,r,k);
        }
        else{
            int l,r;
            cin >> l >> r;
            cout << st.query(1,1,n,l,r) << '\n';
        }
    } 
}


int32_t main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi 
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while (t --> 0) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...