Submission #1342900

#TimeUsernameProblemLanguageResultExecution timeMemory
1342900GervidDeda (COCI17_deda)C++20
140 / 140
712 ms7764 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <array>

using namespace std;
using ll = long long;

vector<ll> tree; //on age, the min distance

void insert(int l, int r, int x, int xr, ll val) {
	if (l == r) {
		tree[x] = val;
		return;
	}
	int m = (l + r) / 2;
	if (xr <= m) insert(l, m, 2 * x + 1, xr, val);
	else insert(m + 1, r, 2 * x + 2, xr, val);
	tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]);
}

ll query(int l, int r, int x, int lq, int rq) {
	if (lq <= l && r <= rq) return tree[x];
	if (rq < l || r < lq) return INT_MAX;
	int m = (l + r) / 2;
	return min(query(l, m, 2 * x + 1, lq, rq), query(m+1, r, 2*x+2, lq, rq));
}

signed main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, q;
	cin >> n >> q;
	tree.resize(4 * n, INT_MAX);

	while (q--) {
		char type;
		int y, b;
		cin >> type >> y >> b;
		if (type == 'M') {
			insert(0, n, 0, b, y);
		}
		else {
			int l = b, r = n+1, m;
			while (l < r) {	
				m = (l + r) / 2;
				if (query(0, n, 0, b, m) <= y) {
					r = m;
				}
				else {
					l = m+1;
				}
			}
			if (r == n+1) {
				cout << -1 << '\n';
			}
			else cout << l << '\n';
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...