제출 #1290576

#제출 시각아이디문제언어결과실행 시간메모리
1290576hamza_28Deda (COCI17_deda)C++20
20 / 140
54 ms4284 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 3, inf = 1e9 + 9; struct ST { #define lc (n << 1) #define rc ((n << 1) + 1) int t[4 * N]; ST() { memset(t, 0, sizeof t); } inline void pull(int n) { t[n] = min(t[lc], t[rc]); } void build(int n, int b, int e) { if (b == e) { t[n] = inf; return; } int mid = (b + e) >> 1; build(lc, b, mid); build(rc, mid + 1, e); pull(n); } void upd(int n, int b, int e, int i, int val) { if (i < b || e < i) return; if (b == e) { t[n] = val; return; } int mid = (b + e) >> 1; upd(lc, b, mid, i, val); upd(rc, mid + 1, e, i, val); pull(n); } int query(int n, int b, int e, int i, int val) { if (t[n] > val || e < i) return inf; if (b == e) { return b; } int mid = (b + e) >> 1; if (t[lc] > val || mid < i) { return query(rc, mid + 1, e, i, val); } return query(lc, b, mid, i, val); } }t; void solve() { int n, m; cin >> n >> m; t.build(1, 1, n); while (m--) { char c; int x, y; cin >> c >> x >> y; if (c == 'M') { t.upd(1, 1, n, y, x); } else { int ans = t.query(1, 1, n, y, x); if (ans == inf) ans = -1; cout << ans << '\n'; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...