Submission #545390

#TimeUsernameProblemLanguageResultExecution timeMemory
545390noeditDeda (COCI17_deda)C++17
120 / 140
1030 ms3356 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 l, int r) { if (l > r || l < tl || tr < r) return INF; if (tl == l && tr == r) { return t[v]; } int tm = (tl + tr) >> 1; int ql = get(v * 2, tl, tm, l, min(r, tm)); int qr = get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r); 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 l = b - 1, r = n - 1; while (r - l > 1) { int mid = (l + r) >> 1; if (get(1, 0, n - 1, b, mid) <= y) { r = mid; } else { l = mid; } } if (get(1, 0, n - 1, b, r) > y) cout << -1 << '\n'; else cout << r + 1 << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...