Submission #406696

# Submission time Handle Problem Language Result Execution time Memory
406696 2021-05-18T03:11:54 Z tengiz05 Street Lamps (APIO19_street_lamps) C++17
0 / 100
84 ms 776 KB
#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, q;
    std::cin >> n >> q;
    std::string v;
    std::cin >> v;
    segtree s(n, 1e9);
    for (int i = 0; i < n; i++) {
        if (v[i] == '1') {
            s.update(i, -1);
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << s.get(i, i) << ' ';
    }
    std::cout << '\n';
    for (int it = 0; it < q; it++) {
        std::string type;
        std::cin >> type;
        if (type == "query") {
            int l, r;
            std::cin >> l >> r;
            l--;
            r-=2;
            int res = it - s.get(l, r);
            std::cout << std::max(0, res) << '\n';
        } else {
            int p;
            std::cin >> p;
            p--;
            s.update(p, it);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -