# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
162007 |
2019-11-05T18:03:34 Z |
DS007 |
Deda (COCI17_deda) |
C++14 |
|
1000 ms |
8044 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
const int M = 1e9 + 1;
#define child 2 * v;
int t[4 * N];
int n, q;
void update(int v, int tl, int tr, int a, int x) {
if (a == tl && tl == tr) {
t[v] = x;
} else {
int tm = (tl + tr) / 2;
if (a <= tm)
update(v * 2, tl, tm, a, x);
else
update(v * 2 + 1, tm + 1, tr, a, x);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
}
int query(int v, int tl, int tr, int l, int r, int y) {
if (l == tl && r == tr && l == r)
return l;
int tm = (tl + tr) / 2, a = -2, b = -2;
if (t[v * 2] <= y && l <= tm)
a = query(v * 2, tl, tm, l, min(tm, r), y);
if (t[v * 2 + 1] <= y && r > tm)
b = query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, y);
return a == -2 ? b : (b == -2 ? a : min(a, b));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
fill(t, t + 4 * N, M);
cin >> n >> q;
for (int i = 0; i < q; i++) {
char m;
int x, a;
cin >> m >> x >> a;
if (m == 'M')
update(1, 0, n - 1, a - 1, x);
else
cout << query(1, 0, n - 1, a - 1, n - 1, x) + 1 << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
13 ms |
3576 KB |
Output is correct |
4 |
Correct |
454 ms |
8044 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
4472 KB |
Time limit exceeded |
6 |
Execution timed out |
1061 ms |
4524 KB |
Time limit exceeded |
7 |
Execution timed out |
1074 ms |
4472 KB |
Time limit exceeded |