This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |