Submission #545394

#TimeUsernameProblemLanguageResultExecution timeMemory
545394noeditDeda (COCI17_deda)C++17
140 / 140
148 ms3416 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("avx") using namespace std; using namespace __gnu_pbds; typedef long double ld; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //#define int long long typedef long long ll; const int MAXN = 2e5; const int INF = 2e9; int t[4 * MAXN]; void build(int v, int tl, int tr) { if (tl == tr) { t[v] = INF; } else { int tm = (tl + tr) >> 1; build(v * 2, tl, tm); build(v * 2 + 1, tm + 1, tr); t[v] = min(t[v * 2], t[v * 2 + 1]); } } void update(int v, int tl, int tr, int p, int x) { if (tl == tr) { t[v] = x; return; } int tm = (tl + tr) >> 1; if (p <= tm) update(v * 2, tl, tm, p, x); else update(v * 2 + 1, tm + 1, tr, p, x); t[v] = min(t[v * 2], t[v * 2 + 1]); } int get(int v, int tl, int tr, int y) { if (tl == tr) { if (t[v] <= y) return tl; else return INF; } int tm = (tl + tr) >> 1; if (t[v * 2] <= y) return get(v * 2, tl, tm, y); else if (t[v * 2 + 1] <= y) return get(v * 2 + 1, tm + 1, tr, y); return INF; } int get(int v, int tl, int tr, int l, int r, int y) { if (l > r || l < tl || tr < r) return INF; if (tl == l && tr == r) { return get(v, tl, tr, y); } int tm = (tl + tr) >> 1; int ql = get(v * 2, tl, tm, l, min(r, tm), y); int qr = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, y); return min(ql, qr); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; build(1, 0, n - 1); while (q--) { char c; cin >> c; if (c == 'M') { int x, a; cin >> x >> a; a--; update(1, 0, n - 1, a, x); } else { int y, b; cin >> y >> b; b--; int ans = get(1, 0, n - 1, b, n - 1, y); if (ans == INF) cout << -1 << '\n'; else cout << ans + 1 << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...