Submission #237069

#TimeUsernameProblemLanguageResultExecution timeMemory
237069MrRobot_28Deda (COCI17_deda)C++17
140 / 140
139 ms8056 KiB
#include<bits/stdc++.h> using namespace std; vector <int> tree; void update(int v, int l, int r, int ind, int val) { if(l == r) { tree[v] = val; return; } if(ind <= (r + l) / 2) { update(v * 2, l, (r + l) / 2, ind, val); } else { update(v * 2 + 1, (r + l) / 2 + 1, r, ind, val); } tree[v] = min(tree[v * 2], tree[v * 2 + 1]); } int ans(int v, int l, int r, int al, int ar, int y) { if(l >= al && r <= ar) { if(tree[v] > y) { return -1; } if(l == r) { return l + 1; } if(tree[v * 2] <= y) { return ans(v * 2, l, (r + l) / 2, al, ar, y); } return ans(v * 2 + 1, (r + l) / 2 + 1, r, al, ar, y); } else if(l <= ar && r >= al) { int t = ans(v * 2, l, (r + l) / 2, al, ar, y); if(t == -1) { return ans(v * 2 + 1, (r + l) / 2 + 1, r, al, ar, y); } return t; } else { return -1; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, q; cin >> n >> q; tree.resize(4 * n, 1e9); while(q--) { char t; cin >> t; if(t == 'M') { int x, a; cin >> x >> a; a--; update(1, 0, n - 1, a, x); } else { int y, b; cin >> y >> b; b--; cout << ans(1, 0, n - 1, b, n - 1, y) << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...