#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
struct segtree{
int sz = 1, lim; const int ID = 1e10;
vector<int> a;
segtree(int n){
while(sz < n) sz *= 2;
lim = n;
a.assign(2*sz, ID);
}
void update(int i, int val, int x, int lx, int rx){
if(rx-lx==1) return void(a[x] = val);
int mx = (lx+rx)/2;
if(i<mx) update(i, val, 2*x+1, lx, mx);
else update(i, val, 2*x+2, mx, rx);
a[x] = min(a[2*x+1], a[2*x+2]);
}
void update(int i, int val){ update(i, val, 0, 0, sz); }
int get(int l, int val, int x, int lx, int rx){
if(rx<=l) return ID;
if(rx-lx==1) return (lx>=l ? lx : ID);
int mx = (lx+rx)/2;
int res = ID;
if(a[2*x+1]<=val) res = get(l, val, 2*x+1, lx, mx);
if(res==ID and a[2*x+2]<=val) res = get(l, val, 2*x+2, mx, rx);
return res;
}
int get(int l, int val){
int res = get(l, val, 0, 0, sz);
return (res==ID or res>=lim? -1 : res+1);
}
};
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, q; cin >> n >> q;
segtree st(n);
char c;
int x, y;
while(q--){
cin >> c >> x >> y;
if(c=='M') st.update(y-1, x);
else cout << st.get(y-1, x) nl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
364 KB |
Output is correct |
4 |
Correct |
94 ms |
8940 KB |
Output is correct |
5 |
Correct |
114 ms |
6528 KB |
Output is correct |
6 |
Correct |
133 ms |
8812 KB |
Output is correct |
7 |
Correct |
137 ms |
8892 KB |
Output is correct |