# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920177 | vjudge1 | Deda (COCI17_deda) | C++17 | 130 ms | 7748 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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+1) 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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |