Submission #171561

#TimeUsernameProblemLanguageResultExecution timeMemory
171561mcdx9524Simple game (IZhO17_game)C++14
0 / 100
2 ms504 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6; ll t[4 * N]; ll lz[4 * N]; void push(int v, int tl, int tr) { if (!lz[v]) { return; } t[v] += lz[v] * (tr - tl + 1); if (tl != tr) { lz[2 * v + 1] += lz[v]; lz[2 * v + 2] += lz[v]; } lz[v] = 0; } void upd(int v, int tl, int tr, int l, int r, int x) { push(v, tl, tr); if (l > tr || r < tl) { return; } else if (l <= tl && tr <= r) { lz[v] += x; push(v, tl, tr); return; } else { int tm = (tl + tr) / 2; upd(2 * v + 1, tl, tm, l, r, x); upd(2 * v + 2, tm + 1, tr, l, r, x); t[v] = t[2 * v + 1] + t[2 * v + 2]; } } ll get(int v, int tl, int tr, int l, int r) { push(v, tl, tr); if (l > tr || r < tl) { return 0; } else if (l <= tl && tr <= r) { return t[v]; } else { int tm = (tl + tr) / 2; return get(2 * v + 1, tl, tm, l, r) + get(2 * v + 2, tm + 1, tr, l, r); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector <int> h(n); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 1; i < n; i++) { upd(0, 0, N - 1, min(h[i], h[i - 1]), max(h[i], h[i - 1]), 1); } for (int it = 0; it < m; it++) { int t; cin >> t; if (t == 1) { int pos, val; cin >> pos >> val; pos--; if (pos != 0) { upd(0, 0, N - 1, min(h[pos], h[pos - 1]), max(h[pos], h[pos - 1]), -1); } if (pos != n - 1) { upd(0, 0, N - 1, min(h[pos], h[pos + 1]), max(h[pos], h[pos - 1]), -1); } h[pos] = val; if (pos != 0) { upd(0, 0, N - 1, min(h[pos], h[pos - 1]), max(h[pos], h[pos - 1]), 1); } if (pos != n - 1) { upd(0, 0, N - 1, min(h[pos], h[pos + 1]), max(h[pos], h[pos - 1]), 1); } } else { int hg; cin >> hg; cout << get(0, 0, N - 1, hg, hg) << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...