Submission #745059

#TimeUsernameProblemLanguageResultExecution timeMemory
745059rt144Street Lamps (APIO19_street_lamps)C++17
20 / 100
172 ms38984 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]; 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); cout << st[a-1].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...