# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386058 | 2021-04-05T14:15:33 Z | Kalashnikov | Simple game (IZhO17_game) | C++17 | 1000 ms | 8204 KB |
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; const int N = 1e5+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7 , P = 6547; int h[N] , u[N] , ans[N] , pos[N] , val[N] , type[N] , prank[N]; int K = 2; struct node{ int l ,r , pix; }t[4*N]; int n , q; void upd(int pos , int val = 1 , int u = 1, int ul = 1, int ur = n) { if(ul == ur) { t[u].l = val; t[u].r = val; return; } int um = ul+ur >> 1; if(pos <= um) { upd(pos , val , u<<1 , ul , um); } else { upd(pos , val , u<<1|1 , um+1 , ur); } t[u].l = t[u<<1].l; t[u].r = t[u<<1|1].r; t[u].pix = t[u<<1].pix + t[u<<1|1].pix + (t[u<<1].r != t[u<<1|1].l); } void solve() { cin >> n >> q; for(int i = 1; i <= n; i ++) { cin >> h[i]; } for(int i = 0; i <= q; i ++) { if((i%K == 0 && i != 0) || i == q) { vector<pair<int,int>> cons; for(int i = 1; i <= n; i ++) { if(u[i] == 0) { cons.push_back({h[i] , i}); } u[i] = 0; } sort(all(cons)); reverse(all(cons)); vector<pair<int,int>> ques; vector<int> changes; for(int j = max(i-K , 0); j < i; j ++) { if(type[j] == 1) { changes.push_back(j); } else { ques.push_back({val[j] , j}); } } // cout << "QUES\n"; sort(all(ques)); for(auto x: changes) { prank[x] = h[pos[x]]; } for(auto to: ques) { while(cons.size() && cons.back().F < to.F) { upd(cons.back().S); cons.pop_back(); } for(auto x: changes) { if(x > to.S) break; h[pos[x]] = val[x]; } for(auto x: changes) { if(h[pos[x]] < to.F) { upd(pos[x]); } } ans[to.S] = t[1].pix; for(auto x: changes) { upd(pos[x] , 0); h[pos[x]] = prank[x]; } } for(auto x: changes) { h[pos[x]] = val[x]; } for(int i = 0; i < 4*N; i ++) t[i].pix = t[i].l = t[i].r = 0; } if(i == q) break; cin >> type[i]; if(type[i] == 1) { cin >> pos[i] >> val[i]; u[pos[i]] = 1; } else { cin >> val[i]; } } for(int i = 0; i < q; i ++) { if(type[i] == 2) cout << ans[i] << '\n'; } } /* */ main() { ios; int tt = 1; // cin >> tt; while(tt --) { solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5100 KB | Output is correct |
2 | Correct | 346 ms | 5228 KB | Output is correct |
3 | Correct | 347 ms | 5100 KB | Output is correct |
4 | Correct | 344 ms | 5100 KB | Output is correct |
5 | Correct | 341 ms | 5100 KB | Output is correct |
6 | Correct | 349 ms | 5228 KB | Output is correct |
7 | Correct | 329 ms | 5356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5100 KB | Output is correct |
2 | Correct | 346 ms | 5228 KB | Output is correct |
3 | Correct | 347 ms | 5100 KB | Output is correct |
4 | Correct | 344 ms | 5100 KB | Output is correct |
5 | Correct | 341 ms | 5100 KB | Output is correct |
6 | Correct | 349 ms | 5228 KB | Output is correct |
7 | Correct | 329 ms | 5356 KB | Output is correct |
8 | Execution timed out | 1092 ms | 8204 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5100 KB | Output is correct |
2 | Correct | 346 ms | 5228 KB | Output is correct |
3 | Correct | 347 ms | 5100 KB | Output is correct |
4 | Correct | 344 ms | 5100 KB | Output is correct |
5 | Correct | 341 ms | 5100 KB | Output is correct |
6 | Correct | 349 ms | 5228 KB | Output is correct |
7 | Correct | 329 ms | 5356 KB | Output is correct |
8 | Execution timed out | 1092 ms | 8204 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |