Submission #745050

#TimeUsernameProblemLanguageResultExecution timeMemory
745050rt144Street Lamps (APIO19_street_lamps)C++17
0 / 100
95 ms24388 KiB
#include <bits/stdc++.h> 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, 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].insert({1, inf}); 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); } } }
#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...