Submission #745069

#TimeUsernameProblemLanguageResultExecution timeMemory
745069rt144Street Lamps (APIO19_street_lamps)C++17
40 / 100
5079 ms35364 KiB
#include <bits/stdc++.h> // #include <icecream.hpp> using namespace std; const int maxn = 3e5+5, inf = 2*maxn; struct bst : set<pair<int, int>> { int prev = 0; int get_times(int x) { if (!empty() && rbegin()->second>=x) { return prev + x-rbegin()->first+1; } else return prev; } void toggle(int x) { if (empty() || rbegin()->second<x) { insert({x+1, inf}); } else { int start = rbegin()->first; erase(--end()); insert({start, x}); prev += x-start+1; } } }; // using bst = set<pair<int, int>>; int n, q; bst st[maxn]; bst merge(bst &a, bst &b) { if (a.empty()) return a; if (b.empty()) return b; auto ai = a.begin(), bi = b.begin(); bst nxt{}; while (ai!=a.end() && bi!=b.end()) { auto [al, ar] = *ai; auto [bl, br] = *bi; if (al > br) bi++; else if (bl > ar) ai++; else { int l = max(al, bl), r = min(ar, br); nxt.insert({l, r}); if (ar>br) bi++; else ai++; } } for (auto [l, r] : nxt) if (r!=inf) nxt.prev += r-l+1; return nxt; } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> q; string init; cin >> init; for (int i=0;i<n;i++) if (init[i]=='1') st[i].toggle(0); // IC(st[0]); for (int i=1;i<=q;i++) { string res; cin >> res; if (res=="query") { int a, b; cin >> a >> b; //assert(b-a==1); bst res = st[a-1]; for (int i=a;i<b-1;i++) { res = merge(res, st[i]); } cout << res.get_times(i) << '\n'; } else { int a; cin >> a; st[a-1].toggle(i); } // IC(i, st[0]); } }
#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...