Submission #920154

#TimeUsernameProblemLanguageResultExecution timeMemory
920154vjudge1Deda (COCI17_deda)C++17
0 / 140
130 ms11692 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") #define int long long #define vb vector<bool> #define vvb vector<vb> #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vpi vector<pii> #define vvpi vector<vpi> #define fi first #define se second #define F(i, s, e) for (int i = s; i < e; i++) #define endl '\n' #define sp << ' ' << #define pb push_back const int MOD = 1e9 + 7; const int inf = 1e16; const int N = 2e5 + 7; int t[4*N]; int a[N]; void build(int node, int l, int r) { if(l == r) { t[node] = a[l]; return; } int m = (l + r) >> 1; build(node*2+1, l, m); build(node*2+2, m+1, r); t[node] = min(t[node*2+1], t[node*2+2]); } void update(int node, int l, int r, int i, int v) { if(l > i || r < i) return; if(l == r) { t[node] = v; return; } int m = (l + r) >> 1; update(node*2+1, l, m, i, v); update(node*2+2, m+1, r, i, v); t[node] = min(t[node*2+1], t[node*2+2]); } int walk(int node, int l, int r, int L, int R, int v) { if(l > R || r < L) return inf; int m = (l + r) >> 1; if(l == r) { if(t[node] <= v) return l; return inf; } if(l >= L && r <= R) { if(t[node*2+1] <= v) return walk(node*2+1, l, m, L, R, v); if(t[node*2+2] <= v) return walk(node*2+2, m+1, r, L, R, v); return inf; } return min(walk(node*2+1, l, m, L, R, v), walk(node*2+2, m+1, r, L, R, v)); } void solve() { int n, q; cin >> n >> q; F(i, 0, n) a[i] = inf; build(0, 1, n); string s; int x, y; F(i, 0, q) { cin >> s >> x >> y; if(s[0] == 'D') { int res = walk(0, 1, n, y, n, x); if(res == inf) cout << -1 << endl; else cout << res << endl; } else { //cout << "updating" << endl; update(0, 1, n, y, x); } } } void setIO() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef Local freopen("local.in", "r", stdin); freopen("local.out", "w", stdout); #endif } int32_t main() { setIO(); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...