# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941649 | blacktulip | Deda (COCI17_deda) | C++17 | 643 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> vec;
set<int> st[li*2];
inline void update(int p,int start,int end,int l,int r,int x){
p+=n;
st[p].insert(x);
while(p>1){
p/=2;
st[p].insert(x);
}
}
inline void query(int node,int start,int end,int l,int r,int x){
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l&1){
auto it=st[l].lower_bound(x);
if(it!=st[l].end()){cev=min(cev,*it);}
l++;
}
if (r&1){
r--;
auto it=st[r].lower_bound(x);
if(it!=st[r].end()){cev=min(cev,*it);}
}
}
}
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(x[i]-1,1,t,x[i]-1,x[i]-1,y[i]);
}
else{
cev=inf;
query(1,1,t,0,x[i],y[i]);
if(cev==inf)cev=-1;
cout<<cev<<endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |