#include <bits/stdc++.h>
using namespace std;
const int mxN=2e5;
int n, q, a, b, st[1<<19];
char qt;
void upd(int l1, int x, int i=1, int l2=0, int r2=n-1) {
st[i]=min(x, st[i]);
if(l2==r2)
return;
int m2=(l2+r2)/2;
if(l1<=m2)
upd(l1, x, 2*i, l2, m2);
else
upd(l1, x, 2*i+1, m2+1, r2);
}
int qry(int l1, int x, int i=1, int l2=0, int r2=n-1) {
if(st[i]>x)
return -2;
if(l2==r2)
return l2;
int m2=(l2+r2)/2;
int r=-2;
if(l1<=m2)
r=qry(l1, x, 2*i, l2, m2);
if(r==-2)
r=qry(l1, x, 2*i+1, m2+1, r2);
return r;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
memset(st, 0x3f, sizeof(st));
while(q--) {
cin >> qt >> a >> b, --b;
if(qt=='M')
upd(b, a);
else
cout << qry(b, a)+1 << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2424 KB |
Output is correct |
2 |
Correct |
5 ms |
2432 KB |
Output is correct |
3 |
Correct |
7 ms |
2496 KB |
Output is correct |
4 |
Correct |
100 ms |
6820 KB |
Output is correct |
5 |
Correct |
107 ms |
6820 KB |
Output is correct |
6 |
Correct |
134 ms |
6820 KB |
Output is correct |
7 |
Correct |
115 ms |
6820 KB |
Output is correct |