답안 #570422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570422 2022-05-29T18:06:58 Z saarang123 Deda (COCI17_deda) C++17
140 / 140
105 ms 7568 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MXN = 200 * 1000 + 3;
array<int, 2> t[MXN << 2];
int n, q;

void update(int v, int tl, int tr, int pos, int val) {
	if(tl == tr)
		return t[v] = {val, pos}, void();
	int tm = (tl + tr) >> 1;
	if(pos <= tm)
		update(v << 1, tl, tm, pos, val);
	else
		update(v << 1|1, tm + 1, tr, pos, val);
	t[v] = min(t[v << 1], t[v << 1|1]);
}

void upd(int x, int val) { update(1, 1, n, x, val); }

array<int, 2> query(int v, int tl, int tr, int l, int r, int y) {
	if(l > tr || r < tl)
		return array<int, 2>{(int) 1e9 + 4, -1};
	if(tl == tr)
		return t[v];
	if(l <= tl && tr <= r) {
		if(t[v][0] > y)
			return array<int, 2>{(int) 1e9 + 4, -1};
		int tm = (tl + tr) >> 1;
		auto q1 = t[v << 1];
		if(q1[0] <= y)
			return query(v << 1, tl, tm, l, r, y);
		else
			return query(v << 1|1, tm + 1, tr, l, r, y);
	}
	int tm = (tl + tr) >> 1;
	auto q1 = query(v << 1, tl, tm, l, r, y);
	//cout << tl << ' ' << tr << " range: " << q1[0] << ' ' << q2[0] << endl;
	if(q1[0] <= y)
		return q1;
	else
		return query(v << 1|1, tm + 1, tr, l, r, y);
}

int query(int x, int y) {
	auto ok = query(1, 1, n, x, n, y);
	//cout << ok[0] << ' ' << ok[1] << '\n';
	if(ok[0] > y)
		return -1;
	return ok[1];
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    memset(t, 0x5f, sizeof t);
    cin >> n >> q;
    while(q--) {
    	char c; cin >> c;
    	if(c == 'M') {
    		int a, x;
    		cin >> x >> a;
    		upd(a, x);
    	} else {
    		int y, x;
    		cin >> y >> x;
    		cout << query(x, y) << '\n';
    	}
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 4 ms 6532 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 99 ms 7568 KB Output is correct
5 Correct 100 ms 7304 KB Output is correct
6 Correct 105 ms 7368 KB Output is correct
7 Correct 101 ms 7480 KB Output is correct