제출 #445964

#제출 시각아이디문제언어결과실행 시간메모리
445964dxz05Simple game (IZhO17_game)C++14
100 / 100
209 ms6920 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 3e2; int f[MAXN]; void add(int i, int x){ while (i < MAXN){ f[i] += x; i += (-i & i); } } void add(int l, int r, int x){ if (l > r) swap(l, r); add(l, x); add(r + 1, -x); } int get(int i){ int res = 0; while (i > 0){ res += f[i]; i -= (-i & i); } return res; } int a[MAXN]; int main(){ ios_base::sync_with_stdio(false); int n, q; cin >> n >> q; for (int i = 1; i <= n; i++){ cin >> a[i]; if (i > 1) add(a[i - 1], a[i], 1); } while (q--){ int t; cin >> t; if (t == 1){ int i, x; cin >> i >> x; if (i > 1){ add(a[i - 1], a[i], -1); add(a[i - 1], x, 1); } if (i < n){ add(a[i], a[i + 1], -1); add(x, a[i + 1], 1); } a[i] = x; } else { int h; cin >> h; cout << get(h) << endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...