Submission #229660

# Submission time Handle Problem Language Result Execution time Memory
229660 2020-05-05T18:05:05 Z vee_nits123 Deda (COCI17_deda) C++14
140 / 140
117 ms 7928 KB
#include <iostream>
#include <climits>
#include <cstring>

using namespace std;

#define int long long int
#define endl '\n'

const int N = 2e5 + 5;
//const int M = 1e9 + 1;
int tree[4 * N];

void update(int ind, int val, int st, int end, int pos) {
	if (st > end || ind > end || ind < st) return ;
	if (st == end && st == ind) {
		tree[pos] = val;
		return ;
	}
	int mid = (st + end) / 2;
	//if(ind<=mid)
	update(ind, val, st, mid, 2 * pos);
	//else
	update(ind, val, mid + 1, end, 2 * pos + 1);
	tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
	return ;
}

int query(int l, int r, int val, int st, int end, int pos) {
	if (st > end) return INT_MAX;
	if (st == l && r == end && l == r)
		return l;
	int mid = (st + end) / 2;
	int a = -1, b = -1;
	if (tree[2 * pos] <= val && l <= mid) {
		a = query(l, min(mid, r), val, st, mid, 2 * pos);
	}
	if (a == -1 && tree[2 * pos + 1] <= val && r > mid) {
		b = query(max(l, mid + 1), r, val, mid + 1, end, 2 * pos + 1);
	}
	if (a == -1)
		return b;
	else {
		if (b == -1)
			return a;
		else
			return min(a, b);
	}
}

int32_t main() {

	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	// code starts

	//int t;cin>>t;while(t--){}

	fill(tree, tree + 4 * N, INT_MAX);

	int n, q; cin >> n >> q;
	while (q--) {
		char x;
		int val, ind; cin >> x >> val >> ind;
		if (x == 'M') {
			update(ind, val, 1, n, 1);
		}
		else {
			cout << query(ind, n, val, 1, n, 1) << endl;
		}
	}


	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6656 KB Output is correct
2 Correct 8 ms 6656 KB Output is correct
3 Correct 9 ms 6656 KB Output is correct
4 Correct 95 ms 7928 KB Output is correct
5 Correct 104 ms 7672 KB Output is correct
6 Correct 114 ms 7800 KB Output is correct
7 Correct 117 ms 7928 KB Output is correct