답안 #876607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876607 2023-11-22T05:28:50 Z vjudge1 Deda (COCI17_deda) C++17
140 / 140
747 ms 4640 KB
#include <bits/stdc++.h>

using namespace std;

#define TOF_io ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define file_io freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int) (x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef unsigned long long int ull;

const long long inf = 2147483647, INF = 1e18;
const int md = 1e9 + 7;
const int lg = 30 + 2;
const int sq = 320;
const int N = 200 * 1000 + 5;
const int MAXN = 1000 * 1000 + 5;

int n;
int q;
int seg[N << 2];

void upd(int id, int s, int e, int l, int r, int x) {
	if (r <= s || e <= l) return;
	if (l <= s && e <= r) {
		seg[id] = x;
		return;
	}
	
	int mid = (s + e) / 2;
	upd(2 * id,     s, mid, l, r, x);
	upd(2 * id + 1, mid, e, l, r, x);
	
	seg[id] = min(seg[2 * id], seg[2 * id + 1]);
}

int get(int id, int s, int e, int l, int r) {
	if (r <= s || e <= l) return inf;
	if (l <= s && e <= r) return seg[id];
	
	int mid = (s + e) / 2;
	return min(get(2 * id, s, mid, l, r), get(2 * id + 1, mid, e, l, r));
}

int main() {
	TOF_io;
	cin >> n >> q;
	fill(seg, seg + (N << 2), inf);
	
	for (int i = 0, x, a; i < q; i ++) {
		char c; cin >> c;
		cin >> x >> a;
		
		if (c == 'M') {
			upd(1, 0, n, a - 1, a, x);
		}
		
		else {
			int l = a - 1, r = n;
			
			while (r - l > 1) {
				int mid = (l + r) / 2;
				
				if (get(1, 0, n, l, mid) < x + 1) r = mid;
				else l = mid;
			}
			
			if (get(1, 0, n, l, l + 1) > x) cout << -1 << '\n';
			else cout << l + 1 << '\n';
		}
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3464 KB Output is correct
3 Correct 6 ms 3420 KB Output is correct
4 Correct 747 ms 4640 KB Output is correct
5 Correct 483 ms 4176 KB Output is correct
6 Correct 580 ms 4436 KB Output is correct
7 Correct 647 ms 4560 KB Output is correct