# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941641 | blacktulip | Deda (COCI17_deda) | C++17 | 326 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
#define fi first
#define se second
#define endl "\n"
//~ #define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<
const lo inf = 1000000001;
const lo li = 200005;
const lo mod = 1000000007;
int n,m,k,flag,t,x[li],y[li];
int cev;
char c[li];
string s;
vector<int> v,vec;
set<int> st[li*4];
inline void update(int node,int start,int end,int l,int r,int x){
if(start>end || start>r || end<l)return ;
st[node].insert(x);
if(start>=l && end<=r){return ;}
update(node*2,start,mid,l,r,x),update(node*2+1,mid+1,end,l,r,x);
}
inline void query(int node,int start,int end,int l,int r,int x){
if(start>end || start>r || end<l)return ;
if(start>=l && end<=r){
auto it=st[node].lower_bound(x);
if(it!=st[node].end())cev=min(cev,*it);
return ;
}
query(node*2,start,mid,l,r,x),query(node*2+1,mid+1,end,l,r,x);
}
int main(void){
fio();
cin>>n>>t;
for(int i=1;i<=t;i++){
cin>>c[i]>>x[i]>>y[i];
vec.pb(x[i]);
}
sort(vec.begin(),vec.end());
for(int i=1;i<=t;i++){
x[i]=lower_bound(vec.begin(),vec.end(),x[i])-vec.begin()+1;
//~ cout<<i _ x[i]<<endl;
if(c[i]=='M'){
update(1,1,t,x[i],x[i],y[i]);
}
else{
cev=inf;
query(1,1,t,1,x[i],y[i]);
if(cev==inf)cev=-1;
cout<<cev<<endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |