Submission #1092126

#TimeUsernameProblemLanguageResultExecution timeMemory
1092126juicySimple game (IZhO17_game)C++17
100 / 100
42 ms6872 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 1e5 + 5, M = 1e6 + 5; int n, m; int a[N], s[M]; void upd(int i, int x) { for (; i < M; i += i & -i) { s[i] += x; } } int qry(int i) { int res = 0; for (; i; i -= i & -i) { res += s[i]; } return res; } void add(int u, int v, int x) { upd(min(u, v), x); upd(max(u, v) + 1, -x); } void chg(int i, int v) { if (i < n) { add(a[i], a[i + 1], -1); } if (i > 1) { add(a[i], a[i - 1], -1); } a[i] = v; if (i < n) { add(a[i], a[i + 1], 1); } if (i > 1) { add(a[i], a[i - 1], 1); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (i > 1) { add(a[i], a[i - 1], 1); } } while (m--) { int t; cin >> t; if (t == 1) { int p, v; cin >> p >> v; chg(p, v); } else { int h; cin >> h; cout << qry(h) << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...