Submission #1268847

#TimeUsernameProblemLanguageResultExecution timeMemory
1268847kawhietSimple game (IZhO17_game)C++20
100 / 100
186 ms17832 KiB
#include <bits/stdc++.h> using namespace std; constexpr int N = 1e6; int st[4 * N], lz[4 * N]; void update(int id, int tl, int tr, int l, int r, int v) { if (r < tl || tr < l) return; if (l <= tl && tr <= r) { st[id] += v; lz[id] += v; return; } int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1; update(x, tl, tm, l, r, v); update(y, tm + 1, tr, l, r, v); st[id] = st[x] + st[y] + lz[id]; } int query(int id, int tl, int tr, int l, int r) { if (r < tl || tr < l) return 0; if (l <= tl && tr <= r) return st[id]; int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1; return query(x, tl, tm, l, r) + query(y, tm + 1, tr, l, r) + lz[id]; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { update(0, 0, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1); } while (q--) { int t; cin >> t; if (t == 1) { int i, h; cin >> i >> h; i--; if (i != 0) update(0, 0, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1); if (i != n - 1) update(0, 0, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1); a[i] = h; if (i != 0) update(0, 0, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1); if (i != n - 1) update(0, 0, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1); } else { int x; cin >> x; cout << query(0, 0, N - 1, x, x) << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...