답안 #871993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871993 2023-11-12T05:54:29 Z vjudge1 Deda (COCI17_deda) C++17
60 / 140
71 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define len(x) (int) x.size()
#define pb push_back

struct query {
	char type;
	int a, b;
};

const int N = 3e5 + 7;
map<int, int> mp;
set<int> seg[N << 2];
vector<query> qu;
vector<int> vec;
int n, q;

void read_input() {
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		query t;
		cin >> t.type >> t.a >> t.b;
		vec.pb(t.a);
		qu.pb(t);
	}
}

void prepare() {
	sort(all(vec));
	vec.resize(unique(all(vec)) - vec.begin());
	for (int i = 0; i < len(vec); i++)
		mp[vec[i]] = i;
}

void upd(int p, int x, int id = 1, int st = 0, int en = len(vec)) {
	seg[id].insert(x);
	if (en - st == 1) 
		return;
	int mid = (st + en) >> 1;
	if (p < mid)
		upd(p, x, id << 1, st, mid);
	else
		upd(p, x, id << 1 | 1, mid, en);
}

int get(int l, int r, int b, int id = 1, int st = 0, int en = len(vec)) {
	if (r <= st || l >= en)
		return INT_MAX;
	if (st >= l && en <= r) {
		if (seg[id].empty())
			return INT_MAX;
		if (*(--seg[id].end()) < b)
			return INT_MAX;
		return *seg[id].lower_bound(b);
	}
	int mid = (st + en) >> 1;
	return min(get(l, r, b, id << 1, st, mid), get(l, r, b, id << 1 | 1, mid, en));
}

void solve() {
	for (auto q: qu) {
		char type;
		int a, b;
		type = q.type, a = q.a, b = q.b;
		a = mp[a];
		if (type == 'M') {
			upd(a, b);
		}
		else {
			int t = get(0, a + 1, b);
			cout << (t == INT_MAX? -1: t) << '\n';
		}
	}
}

int32_t main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), prepare(), solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 56668 KB Output is correct
2 Correct 12 ms 56732 KB Output is correct
3 Correct 17 ms 57436 KB Output is correct
4 Runtime error 71 ms 65536 KB Execution killed with signal 9
5 Runtime error 68 ms 65536 KB Execution killed with signal 9
6 Runtime error 69 ms 65536 KB Execution killed with signal 9
7 Runtime error 69 ms 65536 KB Execution killed with signal 9