#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 7;
int n, q, arr[mxN], res[mxN], on[mxN];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
char c;
cin >> c;
if (c == '1') {
arr[i] = 1;
}
on[i] = -1;
}
for (int i = 1; i <= n; ++i) {
if (arr[i]) {
on[i] = 0;
}
}
for (int i = 1; i <= q; ++i) {
string t;
cin >> t;
if (t[0] == 'q') {
int a, b;
cin >> a >> b;
cout << res[a] + (on[a] != -1 ? i - on[a] : 0) << "\n";
}
else {
int ind;
cin >> ind;
arr[ind] ^= 1;
if (arr[ind]) {
assert(on[ind] == -1);
on[ind] = i;
}
else {
res[ind] += i - on[ind];
on[ind] = -1;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
1360 KB |
Output is correct |
2 |
Correct |
49 ms |
1364 KB |
Output is correct |
3 |
Correct |
52 ms |
1360 KB |
Output is correct |
4 |
Correct |
66 ms |
4432 KB |
Output is correct |
5 |
Correct |
70 ms |
4628 KB |
Output is correct |
6 |
Correct |
65 ms |
4692 KB |
Output is correct |
7 |
Correct |
74 ms |
3216 KB |
Output is correct |
8 |
Correct |
77 ms |
5712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |