Submission #85270

#TimeUsernameProblemLanguageResultExecution timeMemory
85270mra2322001Simple game (IZhO17_game)C++14
0 / 100
3 ms700 KiB
#include <bits/stdc++.h> #define f0(i, n) for(int i(0); i < (n); i++) #define f1(i, n) for(int i(1); i <= n; i++) using namespace std; typedef long long ll; const int N = 100002; int n, q, a[N], t[1000002], b[N], c[N]; void up1(int k, int l, int r, int i, int j, int x){ if(r < i || l > j) return ; if(l >= i && r <= j){ t[k] += x; return ; } int m = (l + r)/2; up1(k*2, l, m, i, j, x); up1(k*2 + 1, m + 1, r, i, j, x); } int get1(int k, int l, int r, int i){ if(l==r) return t[k]; int m = (l + r)/2; if(i <= m) return t[k] + get1(k*2, l, m, i); return t[k] + get1(k*2 + 1, m + 1, r, i); } void up(int k1, int k2, int x){ if(k1 > k2) return ; up1(1, 1, 1000000, k1, k2, x); } void solve(){ int h; cin >> h; int x = get1(1, 1, 1000000, h); cout << x << endl; } int main(){ ios_base::sync_with_stdio(0); cin >> n >> q; f1(i, n) cin >> a[i]; for(int i = 2; i <= n; i++){ b[i - 1] = min(a[i - 1], a[i]); c[i - 1] = max(a[i - 1], a[i]); up(b[i - 1] + 1, c[i - 1] - 1, 1); } while(q--){ int type; cin >> type; if(type==2) solve(); else{ int i, x; cin >> i >> x; if(i > 1){ up(b[i - 1] + 1, c[i - 1] - 1, -1); b[i - 1] = min(a[i - 1], x); c[i - 1] = max(a[i - 1], x); up(b[i - 1] + 1, c[i - 1] - 1, 1); } if(i < n){ up(b[i] + 1, c[i] - 1, -1); b[i] = min(a[i + 1], x); c[i] = max(a[i + 1], x); up(b[i] + 1, c[i] - 1, 1); } a[i] += x; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...