Submission #406696

#TimeUsernameProblemLanguageResultExecution timeMemory
406696tengiz05Street Lamps (APIO19_street_lamps)C++17
0 / 100
84 ms776 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, 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 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...