답안 #960027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960027 2024-04-09T14:02:12 Z Blagoj Sterilizing Spray (JOI15_sterilizing) C++17
100 / 100
168 ms 8532 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

int n, q, K;
vector<int> v;

struct SegmentTree {
    vector<ll> sum, mx;

    SegmentTree(int mxn) {
        sum.resize(3 * mxn);
        mx.resize(3 * mxn);
    }

    void pull(int k) {
        mx[k] = max(mx[k * 2], mx[k * 2 + 1]);
        sum[k] = sum[k * 2] + sum[k * 2 + 1];
    }

    void build(int k, int l, int r) {
        if (l == r) {
            sum[k] = mx[k] = v[l];
            return;
        }
        int mid = (l + r) / 2;
        build(k * 2, l, mid);
        build(k * 2 + 1, mid + 1, r);
        pull(k);
    }

    void update1(int k, int l, int r, int i, ll v) {
        if (l > i || r < i) return;
        if (l == r) {
            sum[k] = mx[k] = v;
            return;
        }
        int mid = (l + r) / 2;
        update1(k * 2, l, mid, i, v);
        update1(k * 2 + 1, mid + 1, r, i, v);
        pull(k);
    }

    void update2(int k, int l, int r, int i, int j) {
        if (l > j || r < i || mx[k] == 0) return;
        if (l == r) {
            sum[k] = mx[k] = sum[k] / K;
            return;
        }
        int mid = (l + r) / 2;
        update2(k * 2, l, mid, i, j);
        update2(k * 2 + 1, mid + 1, r, i, j);
        pull(k);
    }

    ll get(int k, int l, int r, int i, int j) {
        if (l > j || r < i) return 0;
        if (i <= l && r <= j) return sum[k];
        int mid = (l + r) / 2;
        return get(k * 2, l, mid, i, j) + get(k * 2 + 1, mid + 1, r, i, j);
    }
} sgt(1e5 + 10); 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q >> K;
    v.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> v[i];
    sgt.build(1, 1, n);
    while (q--) {
        ll t, l, r;
        cin >> t >> l >> r;
        if (t == 1) sgt.update1(1, 1, n, l, r);
        if (t == 2 && K != 1) sgt.update2(1, 1, n, l, r);
        if (t == 3) cout << sgt.get(1, 1, n, l, r) << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 4 ms 5212 KB Output is correct
5 Correct 4 ms 5464 KB Output is correct
6 Correct 4 ms 5212 KB Output is correct
7 Correct 4 ms 5212 KB Output is correct
8 Correct 4 ms 5240 KB Output is correct
9 Correct 4 ms 5212 KB Output is correct
10 Correct 5 ms 5208 KB Output is correct
11 Correct 3 ms 5212 KB Output is correct
12 Correct 4 ms 5252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 7508 KB Output is correct
2 Correct 35 ms 7120 KB Output is correct
3 Correct 36 ms 7248 KB Output is correct
4 Correct 38 ms 8016 KB Output is correct
5 Correct 56 ms 8532 KB Output is correct
6 Correct 47 ms 8284 KB Output is correct
7 Correct 46 ms 8364 KB Output is correct
8 Correct 44 ms 8272 KB Output is correct
9 Correct 45 ms 8272 KB Output is correct
10 Correct 48 ms 8276 KB Output is correct
11 Correct 52 ms 8296 KB Output is correct
12 Correct 43 ms 8272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5720 KB Output is correct
2 Correct 10 ms 5468 KB Output is correct
3 Correct 13 ms 5724 KB Output is correct
4 Correct 37 ms 6400 KB Output is correct
5 Correct 44 ms 6996 KB Output is correct
6 Correct 46 ms 6860 KB Output is correct
7 Correct 43 ms 6992 KB Output is correct
8 Correct 45 ms 7020 KB Output is correct
9 Correct 43 ms 6868 KB Output is correct
10 Correct 49 ms 6936 KB Output is correct
11 Correct 41 ms 6836 KB Output is correct
12 Correct 42 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 6996 KB Output is correct
2 Correct 60 ms 7040 KB Output is correct
3 Correct 66 ms 6472 KB Output is correct
4 Correct 75 ms 7248 KB Output is correct
5 Correct 88 ms 8260 KB Output is correct
6 Correct 97 ms 8092 KB Output is correct
7 Correct 89 ms 8216 KB Output is correct
8 Correct 114 ms 8304 KB Output is correct
9 Correct 124 ms 7964 KB Output is correct
10 Correct 114 ms 8024 KB Output is correct
11 Correct 89 ms 7928 KB Output is correct
12 Correct 168 ms 8020 KB Output is correct