#include <iostream>
#include <algorithm>
#include <vector>
#define MAXV 1000000001
using namespace std;
struct segtree {
vector<int> minS;
int size;
segtree(int n) {
size = n;
minS.resize(4 * n, MAXV);
}
void set(int i, int v, int x, int lx, int rx) {
if (lx + 1 == rx) {
minS[x] = v;
return;
}
int m = (lx + rx) / 2;
if (i < m) {
set(i, v, 2 * x + 1, lx, m);
}
else {
set(i, v, 2 * x + 2, m, rx);
}
minS[x] = min(minS[2 * x + 1], minS[2 * x + 2]);
}
void set(int i, int v) {
set(i, v, 0, 0, size);
}
int get(int l, int r, int v, int x, int lx, int rx) {
if (rx <= l || r <= lx) {
return -1;
}
if (minS[x] > v) {
return -1;
}
if (lx + 1 == rx) {
return lx + 1;
}
int m = (lx + rx) / 2, f = get(l, r, v, 2 * x + 1, lx, m);
return f == -1 ? get(l, r, v, 2 * x + 2, m, rx) : f;
}
int get(int l, int v) {
return get(l, size, v, 0, 0, size);
}
};
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
segtree stS(N);
while (Q--) {
char speaker;
int stop, child;
cin >> speaker >> stop >> child;
--child;
if (speaker == 'M') {
stS.set(child, stop);
}
else {
cout << stS.get(child, stop) << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
76 ms |
7888 KB |
Output is correct |
5 |
Correct |
88 ms |
5808 KB |
Output is correct |
6 |
Correct |
88 ms |
6896 KB |
Output is correct |
7 |
Correct |
108 ms |
7884 KB |
Output is correct |