Submission #1050992

#TimeUsernameProblemLanguageResultExecution timeMemory
1050992manhlinh1501Sterilizing Spray (JOI15_sterilizing)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 1e5 + 5; int N, Q, K; i64 a[MAXN]; struct segment_tree { int N; i64 tree[MAXN * 4]; void build(int id, int l, int r) { if(l == r) { tree[id] = a[r]; return; } int m = (l + r) / 2; build(id * 2, l, m); build(id * 2 + 1, m + 1, r); tree[id] = tree[id * 2] + tree[id * 2 + 1]; } void init(int _N) { N = _N; build(1, 1, N); } void update(int id, int l, int r, int u, int v) { if(r < u or l > v or tree[id] == 0) return; if(u <= l and r <= v) { if(l == r) tree[id] /= K; else if(tree[id] > 0) { int m = (l + r) / 2; update(id * 2, l, m, u, v); update(id * 2 + 1, m + 1, r, u, v); tree[id] = tree[id * 2] + tree[id * 2 + 1]; } return; } int m = (l + r) / 2; update(id * 2, l, m, u, v); update(id * 2 + 1, m + 1, r, u, v); tree[id] = tree[id * 2] + tree[id * 2 + 1]; } void updatep(int p, int x) { int l = 1, r = N, id = 1; while(l < r) { int m = (l + r) / 2; if(p <= m) { id = id * 2; r = m; } else { id = id * 2 + 1; l = m + 1; } } tree[id] = x; while(id > 1) { id >>= 1; tree[id] = tree[id * 2] + tree[id * 2 + 1]; } } void updatep(int p, int x) { return updatep(1, 1, N, p, x); } void update(int l, int r) { return update(1, 1, N, l, r); } i64 get(int id, int l, int r, int u, int v) { if(r < u or l > v) return 0; if(u <= l and r <= v) return tree[id]; int m = (l + r) / 2; return get(id * 2, l, m, u, v) + get(id * 2 + 1, m + 1, r, u, v); } i64 get(int l, int r) { return get(1, 1, N, l, r); } } ST; signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> Q >> K; for(int i = 1; i <= N; i++) cin >> a[i]; ST.init(N); while(Q--) { int type; cin >> type; if(type == 1) { int p, x; cin >> p >> x; ST.updatep(p, x); } else if(type == 2) { int l, r; cin >> l >> r; ST.update(l, r); } else if(type == 3) { int l, r; cin >> l >> r; cout << ST.get(l, r) << "\n"; } } return (0 ^ 0); }

Compilation message (stderr)

sterilizing.cpp:67:10: error: 'void segment_tree::updatep(int, int)' cannot be overloaded with 'void segment_tree::updatep(int, int)'
   67 |     void updatep(int p, int x) {
      |          ^~~~~~~
sterilizing.cpp:48:10: note: previous declaration 'void segment_tree::updatep(int, int)'
   48 |     void updatep(int p, int x) {
      |          ^~~~~~~
sterilizing.cpp: In member function 'void segment_tree::updatep(int, int)':
sterilizing.cpp:68:37: error: no matching function for call to 'segment_tree::updatep(int, int, int&, int&, int&)'
   68 |         return updatep(1, 1, N, p, x);
      |                                     ^
sterilizing.cpp:48:10: note: candidate: 'void segment_tree::updatep(int, int)'
   48 |     void updatep(int p, int x) {
      |          ^~~~~~~
sterilizing.cpp:48:10: note:   candidate expects 2 arguments, 5 provided
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~