Submission #907226

#TimeUsernameProblemLanguageResultExecution timeMemory
907226daoquanglinh2007Simple game (IZhO17_game)C++17
100 / 100
46 ms7000 KiB
#include <bits/stdc++.h> using namespace std; const int NM = 1e5, LIM = 1e6; int N, M, a[NM+5]; int bit[LIM+5]; void update(int x, int val){ while (x <= LIM){ bit[x] += val; x += x & (-x); } } int get(int x){ int res = 0; while (x > 0){ res += bit[x]; x -= x & (-x); } return res; } void upd(int pos, int d){ if (pos > 1){ int l = min(a[pos], a[pos-1])+1, r = max(a[pos], a[pos-1])-1; if (l <= r){ update(l, d); update(r+1, -d); } } if (pos < N){ int l = min(a[pos], a[pos+1])+1, r = max(a[pos], a[pos+1])-1; if (l <= r){ update(l, d); update(r+1, -d); } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 1; i <= N; i++) cin >> a[i]; for (int i = 1; i < N; i++){ int l = min(a[i], a[i+1])+1, r = max(a[i], a[i+1])-1; if (l <= r){ update(l, 1); update(r+1, -1); } } while (M--){ int type; cin >> type; if (type == 1){ int pos, val; cin >> pos >> val; upd(pos, -1); a[pos] = val; upd(pos, 1); } else{ int H; cin >> H; cout << get(H) << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...