Submission #85273

#TimeUsernameProblemLanguageResultExecution timeMemory
85273mra2322001Simple game (IZhO17_game)C++14
100 / 100
229 ms22844 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 up(int x, int y, int id){ for(x; x <= 1000000; x += (x & -x)) t[x] += id; for(y = y + 1; y <= 1000000; y += (y & -y)) t[y] -= id; } int get1(int x){ if(x <= 0) return 0; int res = 0; for(x; x > 0; x -= (x & -x)) res += t[x]; return res; } void solve(){ int h; cin >> h; int x = get1(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; } } }

Compilation message (stderr)

game.cpp: In function 'void up(int, int, int)':
game.cpp:12:10: warning: statement has no effect [-Wunused-value]
     for(x; x <= 1000000; x += (x & -x)) t[x] += id;
          ^
game.cpp: In function 'int get1(int)':
game.cpp:19:10: warning: statement has no effect [-Wunused-value]
     for(x; x > 0; x -= (x & -x)) res += t[x];
          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...