Submission #332206

#TimeUsernameProblemLanguageResultExecution timeMemory
332206vitkishloh228Simple game (IZhO17_game)C++14
100 / 100
561 ms19584 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; const int N = 1000004; int t[4 * N], mod[4 * N]; void push(int v, int l, int r) { if (l == r) { mod[v] = 0; return; } mod[2 * v] += mod[v]; mod[2 * v + 1] += mod[v]; t[2 * v] += mod[v]; t[2 * v + 1] += mod[v]; mod[v] = 0; return; } void upd(int v, int tl, int tr, int l, int r, int x) { push(v, tl, tr); if (tl > tr || l > r) return; if (tl == l && tr == r) { mod[v] += x; t[v] += x; return; } int tm = (tl + tr) >> 1; upd(2 * v, tl, tm, l, min(r, tm), x); upd(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x); } int getelem(int v, int tl, int tr, int pos) { push(v, tl, tr); if (tl == tr) { return t[v]; } int tm = (tl + tr) >> 1; if (pos <= tm) { return getelem(2 * v, tl, tm, pos); } return getelem(2 * v + 1, tm + 1, tr, pos); } int main() { int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n - 1; ++i) { upd(1, 0, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1); } while (q--) { int type; cin >> type; if (type == 2) { int H; cin >> H; cout << getelem(1, 0, N - 1, H) << '\n'; } else { int pos, val; cin >> pos >> val; --pos; if (pos) { upd(1, 0, N - 1, min(a[pos - 1], a[pos]), max(a[pos - 1], a[pos]), -1); } if (pos + 1 < n) { upd(1, 0, N - 1, min(a[pos + 1], a[pos]), max(a[pos + 1], a[pos]), -1); } a[pos] = val; if (pos) { upd(1, 0, N - 1, min(a[pos - 1], a[pos]), max(a[pos - 1], a[pos]), 1); } if (pos + 1 < n) { upd(1, 0, N - 1, min(a[pos + 1], a[pos]), max(a[pos + 1], a[pos]), 1); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...