Submission #942345

# Submission time Handle Problem Language Result Execution time Memory
942345 2024-03-10T13:25:25 Z elotelo966 Deda (COCI17_deda) C++17
140 / 140
96 ms 8020 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define OYY 100000000000005
#define mod 1000000007
#define faster 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 lim 200005
#define fi first
#define se second

int tree[4*lim];
int ans;
bool stop;

inline void build(int node,int start,int end){
	if(start>end)return ;
	if(start==end){
		tree[node]=OYY;
		return ;
	}
	build(node*2,start,mid),build(node*2+1,mid+1,end);
	tree[node]=tree[node*2];
}

inline void update(int node,int start,int end,int l,int r,int val){
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){
		tree[node]=val;
		return;
	}
	update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

inline void query(int node,int start,int end ,int l,int r,int maxi){
	if(start>end || start>r || end<l)return ;
	if(tree[node]>maxi)return ;
	if(stop)return ;
	if(start==end){
		ans=start;
		stop=true;
		return;
	}
	query(node*2,start,mid,l,r,maxi),query(node*2+1,mid+1,end,l,r,maxi);
}

int32_t main(){
	faster
	int n,q;cin>>n>>q;
	build(1,1,n);
	while(q--){
		char c;int x,y;cin>>c>>x>>y;
		if(c=='M'){
			update(1,1,n,y,y,x);
		}
		else{
			ans=-1;stop=false;
			query(1,1,n,y,n,x);
			cout<<ans<<'\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 61 ms 5716 KB Output is correct
5 Correct 78 ms 5676 KB Output is correct
6 Correct 84 ms 7760 KB Output is correct
7 Correct 96 ms 8020 KB Output is correct