제출 #1337500

#제출 시각아이디문제언어결과실행 시간메모리
1337500kawhietSterilizing Spray (JOI15_sterilizing)C++20
컴파일 에러
0 ms0 KiB
a#include <bits/stdc++.h>
using namespace std;

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 0;
        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); }
};

int 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);
        } else {
            cout << t.get(l, r) << '\n';
        }
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sterilizing.cpp:1:2: error: stray '#' in program
    1 | a#include <bits/stdc++.h>
      |  ^
sterilizing.cpp:1:1: error: 'a' does not name a type
    1 | a#include <bits/stdc++.h>
      | ^
sterilizing.cpp:8:5: error: 'vector' does not name a type
    8 |     vector<int> t;
      |     ^~~~~~
sterilizing.cpp: In constructor 'SegmentTree::SegmentTree(int)':
sterilizing.cpp:12:9: error: 't' was not declared in this scope
   12 |         t.resize(4 * n);
      |         ^
sterilizing.cpp: In member function 'void SegmentTree::ass(int, int, int, int, int)':
sterilizing.cpp:21:13: error: 't' was not declared in this scope
   21 |             t[id] = v;
      |             ^
sterilizing.cpp:30:9: error: 't' was not declared in this scope
   30 |         t[id] = t[x] + t[y];
      |         ^
sterilizing.cpp: In member function 'void SegmentTree::update(int, int, int, int, int)':
sterilizing.cpp:34:33: error: 't' was not declared in this scope
   34 |         if (r < tl || tr < l || t[id] == 0) return;
      |                                 ^
sterilizing.cpp:36:13: error: 't' was not declared in this scope
   36 |             t[id] /= k;
      |             ^
sterilizing.cpp:42:9: error: 't' was not declared in this scope
   42 |         t[id] = t[x] + t[y];
      |         ^
sterilizing.cpp: In member function 'int SegmentTree::get(int, int, int, int, int)':
sterilizing.cpp:47:40: error: 't' was not declared in this scope
   47 |         if (l <= tl && tr <= r) return t[id];
      |                                        ^
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:58:5: error: 'ios' has not been declared
   58 |     ios::sync_with_stdio(false);
      |     ^~~
sterilizing.cpp:59:5: error: 'cin' was not declared in this scope
   59 |     cin.tie(nullptr);
      |     ^~~
sterilizing.cpp:78:13: error: 'cout' was not declared in this scope
   78 |             cout << t.get(l, r) << '\n';
      |             ^~~~