제출 #1110427

#제출 시각아이디문제언어결과실행 시간메모리
1110427vladiliusSterilizing Spray (JOI15_sterilizing)C++17
100 / 100
341 ms11740 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

struct ST{
    vector<ll> t;
    int n;
    ST(int ns){
        n = ns;
        t.resize(4 * n);
    }
    void upd(int v, int tl, int tr, int& p, int& x){
        if (tl == tr){
            t[v] = x;
            return;
        }
        int tm = (tl + tr) / 2, vv = 2 * v;
        if (p <= tm){
            upd(vv, tl, tm, p, x);
        }
        else {
            upd(vv + 1, tm + 1, tr, p, x);
        }
        t[v] = t[vv] + t[vv + 1];
    }
    void upd(int p, int x){
        upd(1, 1, n, p, x);
    }
    ll get(int v, int tl, int tr, int& l, int& r){
        if (l > tr || r < tl) return 0;
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2, vv = 2 * v;
        return get(vv, tl, tm, l, r) + get(vv + 1, tm + 1, tr, l, r);
    }
    ll get(int l, int r){
        return get(1, 1, n, l, r);
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, q, k; cin>>n>>q>>k;
    vector<int> a(n + 1);
    ST T(n);
    set<int> st;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
        T.upd(i, a[i]);
        if (a[i]){
            st.insert(i);
        }
    }
    vector<int> all;
    while (q--){
        int s, x, y; cin>>s>>x>>y;
        if (s == 1){
            T.upd(x, y);
            auto it = st.find(x);
            if (it != st.end()){
                st.erase(it);
            }
            if (y) st.insert(x);
            a[x] = y;
        }
        else if (s == 2){
            if (k == 1) continue;
            auto it = st.lower_bound(x);
            all.clear();
            while (it != st.end() && (*it) <= y){
                all.pb((*it));
                it++;
            }
            for (int j: all){
                a[j] /= k;
                T.upd(j, a[j]);
                if (!a[j]){
                    st.erase(j);
                }
            }
        }
        else {
            cout<<T.get(x, y)<<"\n";
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...