Submission #942344

# Submission time Handle Problem Language Result Execution time Memory
942344 2024-03-10T13:24:09 Z elotelo966 Deda (COCI17_deda) C++17
80 / 140
1000 ms 9176 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(start==end){
		ans=min(ans,start);
		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=OYY;stop=false;
			query(1,1,n,y,n,x);
			if(ans!=OYY)cout<<ans<<'\n';
			else cout<<-1<<'\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 252 ms 9176 KB Output is correct
5 Execution timed out 1041 ms 3940 KB Time limit exceeded
6 Execution timed out 1040 ms 6032 KB Time limit exceeded
7 Execution timed out 1059 ms 5960 KB Time limit exceeded