Submission #380054

# Submission time Handle Problem Language Result Execution time Memory
380054 2021-03-20T08:14:29 Z vishesh312 Deda (COCI17_deda) C++17
140 / 140
127 ms 8044 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;

struct SegTree {
    int n;
    vector<int> t;
    SegTree(int _n) {
        n = _n;
        t.resize(4*n, 1e9+5);
    }
    void update(int v, int tl, int tr, int pos, int val) {
        if (tl == tr) {
            t[v] = val;
        } else {
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                update(v*2, tl, tm, pos, val);
            } else {
                update(v*2+1, tm+1, tr, pos, val);
            }
            t[v] = min(t[v*2], t[v*2+1]);
        }
    }
    int query(int v, int tl, int tr, int l, int r, int x) {
        if (r < l) {
            return -2;
        }
        if (t[v] > x) {
            return -2;
        }
        if (tl == tr) {
            return tl;
        }
        int tm = (tl + tr) / 2;
        int q = query(v*2, tl, tm, l, min(tm, r), x);
        if (q != -2) return q;
        return query(v*2+1, tm+1, tr, max(tm + 1, l), r, x);
    }
    void update(int pos, int val) {
        update(1, 0, n-1, pos, val);
    }
    int query(int l, int x) {
        return query(1, 0, n-1, l, n-1, x);
    }
};

void solve(int tc) {
    int n, q;
    cin >> n >> q;
    SegTree seg(n);
    while (q--) {
        char x;
        cin >> x;
        if (x == 'M') {
            int x, a;
            cin >> x >> a;
            seg.update(a-1, x);
        } else {
            int y, b;
            cin >> y >> b;
            cout << seg.query(b-1, y)+1 << '\n';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 96 ms 7952 KB Output is correct
5 Correct 105 ms 6124 KB Output is correct
6 Correct 116 ms 7148 KB Output is correct
7 Correct 127 ms 8044 KB Output is correct