Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code : Earthquakes

#include <atcoder/segtree>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

// (value, index)
using S = pair<int, int>;

S op(S a, S b) { return min(a, b); }

S e() { return {1e9 + 1, -1}; }

void solve() {
    int n, m;
    cin >> n >> m;
    segtree<S, op, e> st(n);

    for (int q = 0; q < m; q++) {
        int type;
        cin >> type;
        if (type == 1) {
            int idx, h;
            cin >> idx >> h;
            st.set(idx, {h, idx});
        } else {
            int l, r, p;
            cin >> l >> r >> p;
            int cnt = 0;
            while (true) {
                auto mn = st.prod(l, r);
                if (mn.first <= p) {
                    st.set(mn.second, e());
                    cnt++;
                } else {
                    break;
                }
            }
            cout << cnt << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();
    return 0;
}