#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <iostream>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
using namespace std;
#define int long long
struct node{
int s, e, m, val;
node *l, *r;
node(int S, int E){
s = S, e = E, m = (s+e)/2;
val=INT_MAX;
if (s!=e){
l = new node(s, m);
r = new node(m+1, e);
}
}
void up(int ind, int nv){
if (s==e)val=nv;
else{
if (ind<=m)l->up(ind, nv);
else r->up(ind, nv);
val = min(l->val, r->val);
}
}
int query(int left, int right, int lim){
if (val>lim)return -1;
if (s==e)return s;
if (right<=m)return l->query(left, right, lim);
if (left>m)return r->query(left, right, lim);
int temp=l->query(left, m, lim);
if (temp!=-1)return temp;
return r->query(m+1, right, lim);
}
}*st;
int32_t main(){
int n, q, a, b;
char c;
cin>>n>>q;
st = new node(1, n);
while (q--){
cin>>c>>a>>b;
if (c=='M')st->up(b, a);
else cout<<st->query(b, n, a)<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |