# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
414654 |
2021-05-30T23:36:26 Z |
fadi57 |
Deda (COCI17_deda) |
C++14 |
|
522 ms |
6904 KB |
#include<bits/stdc++.h>
using namespace std;
const int mx=2e5+5;
typedef long long ll;
int inf=1e9+10;
const int mod=1e9+7;
int n,m,k,p,l,q;
int seg[4*mx];
void build(int node,int st,int en){
if(st==en){
seg[node]=inf;
return;
}
int mid=(st+en)/2;
build(node*2,st,mid); build(node*2+1,mid+1,en);
seg[node]=inf;
return;
}
void update(int node,int st,int en,int idx,int value){
if(st==en){
seg[node]=value;
return;
}
int mid=(st+en)/2;
if(idx<=mid){
update(node*2,st,mid,idx,value);
}else{
update(node*2+1,mid+1,en,idx,value);
}
seg[node]=min(seg[node*2],seg[node*2+1]);
return ;
}
int query(int node,int st,int en,int l,int x){
if(st==en){
if(seg[node]<=x){return st;}else{return -1;}
}
int mid=(st+en)/2;
if(l<=mid&&seg[node*2]<=x){
int z=query(node*2,st,mid,l,x);
if(z!=-1){return z;}
}
if(l<=en&&seg[node*2+1]<=x){
int z=query(node*2+1,mid+1,en,l,x);
if(z!=-1){return z;}
}
return -1;
}
int main(){
cin>>n>>q;
build(1,0,n-1);
// cout<<seg[1]<<endl;
for(int i=0;i<q;i++){
char c;cin>>c;
if(c=='M'){
int x,a;cin>>x>>a;
a--;
update(1,0,n-1,a,x);
// cout<<seg[1]<<endl;
} else{
int y,b;cin>>y>>b;
b--;
int ans=query(1,0,n-1,b,y);
if(ans!=-1){ans++;}
cout<<ans<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
13 ms |
204 KB |
Output is correct |
4 |
Correct |
522 ms |
6728 KB |
Output is correct |
5 |
Correct |
460 ms |
5324 KB |
Output is correct |
6 |
Correct |
463 ms |
6620 KB |
Output is correct |
7 |
Correct |
505 ms |
6904 KB |
Output is correct |