#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);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
16724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
95 ms |
24388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
16764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
16724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
16724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |