답안 #922470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922470 2024-02-05T14:35:00 Z vjudge1 Deda (COCI17_deda) C++17
140 / 140
870 ms 7164 KB
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pb push_back
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pii pair<int, int>
#define st first
#define nd second
#define N 300005
#define L(node) node * 2
#define R(node) node * 2 + 1
#define LOGN 20

int tree[4 * N];
const int INF = 1e9 + 7;

void update(int node, int l, int r, int sl, int val){
	if (l > sl || r < sl) return;
	if (l == sl && r == sl){
		tree[node] = val;
		return;
	}
	int mid = (l+ r) / 2;
	update(L(node), l, mid, sl, val);
	update(R(node), mid + 1, r, sl, val);
	tree[node] = min(tree[L(node)], tree[R(node)]);
}

int query(int node, int l, int r, int sl, int sr){
	if (l > sr || r < sl) return INF;
	if (l >= sl && r <= sr) return tree[node];
	int mid = (l + r) / 2;
	return min(query(L(node), l, mid, sl, sr), query(R(node), mid + 1, r, sl, sr));
}

int32_t main(){
	fastio();

	int n, q;
	cin>>n>>q;
	for (int i = 1; i <= n; i++) update(1, 1, n, i, INF);
	while(q--){
		char t;
		int x, a;
		cin>>t>>x>>a;
		if (t == 'M'){
			update(1, 1, n, a, x);
		}
		else{
			int pos = a;
			for (int i = LOGN; i >= 0; i--){
				int tmp = pos + (1<<i);
				if (tmp <= n && query(1, 1, n, a, tmp) > x) pos = tmp;
			}
			if (query(1, 1, n, a, pos) > x) pos++;
			if (pos > n) cout<<-1<<endl;
			else cout<<pos<<endl; 
		}
	}

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 870 ms 7164 KB Output is correct
5 Correct 534 ms 6688 KB Output is correct
6 Correct 663 ms 6880 KB Output is correct
7 Correct 734 ms 7048 KB Output is correct