답안 #405158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405158 2021-05-15T19:31:42 Z timmyfeng Sterilizing Spray (JOI15_sterilizing) C++17
100 / 100
248 ms 9872 KB
#include <bits/stdc++.h>
using namespace std;

struct segtree {
    segtree *left, *right;
    long long sum;

    segtree(int l, int r, int *c) {
        if (l == r) {
            sum = c[l];
        } else {
            int m = (l + r) / 2;
            left = new segtree(l, m, c);
            right = new segtree(m + 1, r, c);
            sum = left->sum + right->sum;
        }
    }

    void set(int a, int x, int l, int r) {
        if (l == r) {
            sum = x;
        } else {
            int m = (l + r) / 2;
            if (a <= m) {
                left->set(a, x, l, m);
            } else {
                right->set(a, x, m + 1, r);
            }
            sum = left->sum + right->sum;
        }
    }

    void update(int a, int b, int k, int l, int r) {
        if (b < l || r < a || k == 1 || sum == 0) {
            return;
        } else if (l == r) {
            sum /= k;
        } else {
            int m = (l + r) / 2;
            left->update(a, b, k, l, m);
            right->update(a, b, k, m + 1, r);
            sum = left->sum + right->sum;
        }
    }

    long long query(int a, int b, int l, int r) {
        if (b < l || r < a) {
            return 0;
        } else if (a <= l && r <= b) {
            return sum;
        } else {
            int m = (l + r) / 2;
            return left->query(a, b, l, m) + right->query(a, b, m + 1, r);
        }
    }
};

const int N = 100001;

int c[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
    }

    segtree *sum = new segtree(1, n, c);
    while (m--) {
        int t, x, y;
        cin >> t >> x >> y;

        if (t == 1) {
            sum->set(x, y, 1, n);
        } else if (t == 2) {
            sum->update(x, y, k, 1, n);
        } else {
            cout << sum->query(x, y, 1, n) << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 5 ms 464 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 4 ms 592 KB Output is correct
7 Correct 5 ms 684 KB Output is correct
8 Correct 6 ms 588 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 4 ms 588 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 3920 KB Output is correct
2 Correct 53 ms 4484 KB Output is correct
3 Correct 52 ms 7364 KB Output is correct
4 Correct 76 ms 9292 KB Output is correct
5 Correct 87 ms 9820 KB Output is correct
6 Correct 78 ms 9824 KB Output is correct
7 Correct 79 ms 9872 KB Output is correct
8 Correct 84 ms 9848 KB Output is correct
9 Correct 95 ms 9668 KB Output is correct
10 Correct 79 ms 9748 KB Output is correct
11 Correct 74 ms 9652 KB Output is correct
12 Correct 75 ms 9668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 756 KB Output is correct
2 Correct 17 ms 3200 KB Output is correct
3 Correct 21 ms 3308 KB Output is correct
4 Correct 55 ms 1980 KB Output is correct
5 Correct 76 ms 6964 KB Output is correct
6 Correct 76 ms 6960 KB Output is correct
7 Correct 71 ms 7032 KB Output is correct
8 Correct 103 ms 7000 KB Output is correct
9 Correct 76 ms 6972 KB Output is correct
10 Correct 69 ms 6904 KB Output is correct
11 Correct 69 ms 6988 KB Output is correct
12 Correct 72 ms 6936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 3852 KB Output is correct
2 Correct 100 ms 5576 KB Output is correct
3 Correct 105 ms 4548 KB Output is correct
4 Correct 126 ms 4476 KB Output is correct
5 Correct 173 ms 9676 KB Output is correct
6 Correct 163 ms 9644 KB Output is correct
7 Correct 152 ms 9644 KB Output is correct
8 Correct 204 ms 9680 KB Output is correct
9 Correct 173 ms 9524 KB Output is correct
10 Correct 198 ms 9516 KB Output is correct
11 Correct 182 ms 9544 KB Output is correct
12 Correct 248 ms 9480 KB Output is correct