답안 #676503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676503 2022-12-31T03:51:55 Z penguin133 Deda (COCI17_deda) C++17
140 / 140
176 ms 29840 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> > 
#define fi first
#define se second
int n,q;

struct node{
	int s,e,m,val;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e)/2, val = 2e9;
		if(s != e)l = new node(s, m), r= new node(m+1, e);
	}
	void upd(int p, int v){
		if(s == e)val = v;
		else{
			if(p <= m)l->upd(p, v);
			else r->upd(p, v);
			val = min(l->val, r->val);
		}
	}
	int query(int a, int b){
		if(a == s && b == e)return val;
		else if(b <= m)return l->query(a, b);
		else if(a > m)return r->query(a, b);
		else return min(l->query(a, m), r->query(m+1, b));
	}
	int find(int a, int v){
		if(e < a)return -1;
		if(s == e)return (val > v ? -1 : s);
		int x = -1;
		if(l->val <= v)x = l->find(a, v);
		if(x != -1)return x;
		else return r->find(a, v);
	}
}*root;

void solve(){
	cin >> n >> q;
	root = new node(1, n);
	while(q--){
		char x;cin >> x;
		if(x == 'M'){
			int a,b;cin >>a >> b;
			root->upd(b, a);
		}
		else{
			int a, b;cin >>a >> b;
			cout << root->find(b, a) << '\n';
		}
	}
}
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

Compilation message

deda.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 105 ms 29776 KB Output is correct
5 Correct 134 ms 16812 KB Output is correct
6 Correct 171 ms 23372 KB Output is correct
7 Correct 176 ms 29840 KB Output is correct