Submission #507304

#TimeUsernameProblemLanguageResultExecution timeMemory
507304MilosMilutinovicSimple game (IZhO17_game)C++14
100 / 100
180 ms11120 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int st[N * 4]; void modify(int node, int l, int r, int ll, int rr, int x) { if (l > r || l > rr || r < ll) return; if (ll <= l && r <= rr) { st[node] += x; return; } int mid = l + r >> 1; modify(node * 2, l, mid, ll, rr, x); modify(node * 2 + 1, mid + 1, r, ll, rr, x); } int get(int node, int l, int r, int x) { if (l == r) return st[node]; int mid = l + r >> 1; if (x <= mid) return st[node] + get(node * 2, l, mid, x); else return st[node] + get(node * 2 + 1, mid + 1, r, x); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> h(n); for (int i = 0; i < n; i++) { cin >> h[i]; } auto Add = [&](int i) { if (i < 0 || i >= n - 1) return; int L = min(h[i], h[i + 1]); int R = max(h[i], h[i + 1]); modify(1, 1, N, L, R, 1); }; auto Rem = [&](int i) { if (i < 0 || i >= n - 1) return; int L = min(h[i], h[i + 1]); int R = max(h[i], h[i + 1]); modify(1, 1, N, L, R, -1); }; for (int i = 0; i + 1 < n; i++) { Add(i); } while (q--) { int foo; cin >> foo; if (foo == 1) { int pos, val; cin >> pos >> val; --pos; Rem(pos); Rem(pos - 1); h[pos] = val; Add(pos); Add(pos - 1); } else { int H; cin >> H; cout << get(1, 1, N, H) << '\n'; } } return 0; } /* 3 3 1 5 1 2 3 1 1 5 2 3 */

Compilation message (stderr)

game.cpp: In function 'void modify(int, int, int, int, int, int)':
game.cpp:15:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |   int mid = l + r >> 1;
      |             ~~^~~
game.cpp: In function 'int get(int, int, int, int)':
game.cpp:22:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |   int mid = l + r >> 1;
      |             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...