제출 #406750

#제출 시각아이디문제언어결과실행 시간메모리
406750tengiz05다리 (APIO19_bridges)C++17
0 / 100
157 ms2388 KiB
#include <bits/stdc++.h>
struct segtree{
    std::vector<int> t;
    int n;
    segtree(int n, int v) : t(2 * n, v), n(n) { }
    int get(int l, int r){
        int res = -1;
        for (l += n, r += n; l <= r; l >>= 1, r >>= 1) {
            if (l & 1) res = std::max(res, t[l++]);
            if (!(r & 1)) res = std::max(res, t[r--]);
        }
        return res;
    }
    void update(int p, int val){
        for (t[p += n] = val; p > 1; p >>= 1) t[p >> 1] = std::max(t[p], t[p ^ 1]);
    }
};
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, m, q;
    std::cin >> n >> m;
    segtree seg(n + 2, 0);
    for (int i = 0; i < m; i++) {
        int u, v, w;
        std::cin >> u >> v >> w;
        seg.update(i + 1, w);
    }
    std::cin >> q;
    while (q--) {
        int type;
        std::cin >> type;
        if (type == 1) {
            int b, r;
            std::cin >> b >> r;
            b--;
            seg.update(b, r);
        } else {
            int s, W;
            std::cin >> s >> W;
            s--;
            int L, R;
            if (s == 0) L = 0;
            else {
                int l = -1, r = s;
                while (l + 1 < r) {
                    int mid = (l + r) / 2;
                    if (seg.get(mid, s) <= W)
                        r = mid;
                    else 
                        l = mid;
                }
                L = r;
            }
            {
                int l = s, r = n;
                while (l + 1 < r) {
                    int mid = (l + r) / 2;
                    if (seg.get(s, mid) <= W)
                        l = mid;
                    else 
                        r = mid;
                }
                R = l + 1;
            }
            std::cout << R - L << '\n';
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...