제출 #1336466

#제출 시각아이디문제언어결과실행 시간메모리
1336466kawhietDeda (COCI17_deda)C++20
140 / 140
70 ms4592 KiB
#include <bits/stdc++.h>
using namespace std;

constexpr int inf = 1e9;

struct SegmentTree {
    int n;
    vector<int> t;

    SegmentTree(int _n) {
        n = _n;
        t.resize(4 * n);
    }

    int merge(int x, int y) {
        return min(x, y);
    }

    void update(int id, int tl, int tr, int i, int v) {
        if (tl == tr) {
            t[id] = v;
            return;
        }
        int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1;
        if (i <= tm) {
            update(x, tl, tm, i, v);
        } else {
            update(y, tm + 1, tr, i, v);
        }
        t[id] = merge(t[x], t[y]);
    }

    int get(int id, int tl, int tr, int b, int k) {
        if (tr < b || t[id] > k) return -2;
        if (tl == tr) return tl;
        int tm = (tl + tr) >> 1;
        int x = (id << 1) + 1, y = x + 1;
        int res = get(x, tl, tm, b, k);
        if (res != -2) return res;
        return get(y, tm + 1, tr, b, k);
    }

    void update(int i, int v) { update(0, 0, n - 1, i, v); }
    int get(int l, int r) { return get(0, 0, n - 1, l, r); }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    SegmentTree t(n);
    for (int i = 0; i < n; i++) {
        t.update(i, inf);
    }
    while (q--) {
        char c;
        int u, v;
        cin >> c >> u >> v;
        v--;
        if (c == 'M') {
            t.update(v, u);
        } else {
            cout << t.get(v, u) + 1 << '\n';
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...