Submission #1337502

#TimeUsernameProblemLanguageResultExecution timeMemory
1337502kawhietSterilizing Spray (JOI15_sterilizing)C++20
10 / 100
48 ms3824 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int k;

struct SegmentTree {
    int n;
    vector<int> t;

    SegmentTree(int _n) {
        n = _n;
        t.resize(4 * n);
    }

    int merge(int x, int y) {
        return x + y;
    }

    void ass(int id, int tl, int tr, int i, int v) {
        if (tl == tr) {
            t[id] = v;
            return;
        }
        int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1;
        if (i <= tm) {
            ass(x, tl, tm, i, v);
        } else {
            ass(y, tm + 1, tr, i, v);
        }
        t[id] = t[x] + t[y];
    }

    void update(int id, int tl, int tr, int l, int r) {
        if (r < tl || tr < l || t[id] == 0) return;
        if (tl == tr) {
            t[id] /= k;
            return;
        }
        int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1;
        update(x, tl, tm, l, r);
        update(y, tm + 1, tr, l, r);
        t[id] = t[x] + t[y];
    }

    int get(int id, int tl, int tr, int l, int r) {
        if (r < tl || tr < l) return 0LL;
        if (l <= tl && tr <= r) return t[id];
        int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1;
        return merge(get(x, tl, tm, l, r), get(y, tm + 1, tr, l, r));
    }

    void ass(int i, int v) { ass(0, 0, n - 1, i, v); }
    void update(int l, int r) { update(0, 0, n - 1, l, r); }
    int get(int l, int r) { return get(0, 0, n - 1, l, r); }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q >> k;
    SegmentTree t(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        t.ass(i, x);
    }
    while (q--) {
        int c, l, r;
        cin >> c >> l >> r;
        l--; r--;
        if (c == 1) {
            r++;
            t.ass(l, r);
        } else if (c == 2) {
            t.update(l, r && k > 1);
        } else {
            cout << t.get(l, r) << '\n';
        }
    }
    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...