Submission #165782

# Submission time Handle Problem Language Result Execution time Memory
165782 2019-11-28T18:59:56 Z muhi1112 Deda (COCI17_deda) C++17
0 / 140
715 ms 7640 KB
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=1e5+5;

ll n,m,x,y;
pair<int,int>seg[4*N],k;
char c;

void update(int v,int tl,int tr,int pos,int val){
	if(tl==tr){
		seg[v]={val,tl};
	}
	else{
		int tm=(tl+tr)/2;
		if(tm>=pos){
			update(v*2,tl,tm,pos,val);
		}
		else{
			update(v*2+1,tm+1,tr,pos,val);
		}
		seg[v]=min(seg[v*2],seg[v*2+1]);
	}
}
pair<int,int> query(int v,int tl,int tr,int l,int r,int val){
	if(l<=tl && r>=tr){
		return (seg[v].f1)<=val?seg[v]:mp(INT_MAX,-1);
	}
	if(tr<l || tl>r){
		return {INT_MAX,-1};
	}
	int tm=(tl+tr)/2;
	pair<int,int> left=query(v*2,tl,tm,l,r,val);
	pair<int,int> right=query(v*2+1,tm+1,tr,l,r,val);
	if(left.f1<=val && right.f1<=val){
		return left;
	}
	return min(left,right);
}
int main(){
	//fri("in.txt");
	//fro("out.txt");
	cin>>n>>m;
	for(int i=0;i<4*N;i++){
		seg[i]={INT_MAX,-1};
	}
	for(int i=0;i<m;i++){
		cin>>c>>x>>y;
		if(c=='M'){
			update(1,1,n,y,x);
			// for(int j=0;j<2*n;j++){
			// 	cout<<seg[j].f1<<"----"<<seg[j].s2<<"  ";
			// }
			// cout<<endl;
		}
		else{
			k=query(1,1,n,y,n,x);
			cout<<(k.f1==INT_MAX?-1:k.s2)<<endl;
		}
	}
return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3448 KB Output isn't correct
2 Incorrect 6 ms 3448 KB Output isn't correct
3 Incorrect 22 ms 3576 KB Output isn't correct
4 Runtime error 9 ms 6776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Incorrect 715 ms 7640 KB Output isn't correct
6 Runtime error 9 ms 6776 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 9 ms 6904 KB Execution killed with signal 11 (could be triggered by violating memory limits)