#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, q, x, y;
char opr;
struct segtree
{
int d[4*nx];
void update(int l, int r, int i, int idx, int val)
{
if (idx<l||r<idx) return;
if (l==r) return void(d[i]=val);
int md=(l+r)/2;
update(l, md, 2*i, idx, val);
update(md+1, r, 2*i+1, idx, val);
d[i]=min(d[2*i], d[2*i+1]);
}
int query(int l, int r, int i, int B, int Y)
{
if (r<B||d[i]>Y) return -1;
if (l==r) return l;
int md=(l+r)/2, lf=query(l, md, 2*i, B, Y);
if (lf!=-1) return lf;
return query(md+1, r, 2*i+1, B, Y);
}
} s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>q;
for (int i=0; i<4*nx; i++) s.d[i]=1e9+5;
while (q--)
{
cin>>opr>>x>>y;
if (opr=='M') s.update(1, n, 1, y, x);
else cout<<s.query(1, n, 1, y, x)<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3396 KB |
Output is correct |
2 |
Correct |
2 ms |
3400 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
59 ms |
7892 KB |
Output is correct |
5 |
Correct |
81 ms |
7372 KB |
Output is correct |
6 |
Correct |
71 ms |
7712 KB |
Output is correct |
7 |
Correct |
73 ms |
7864 KB |
Output is correct |