#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, Q;
string S;
cin >> N >> Q >> S;
if (N <= 100 && Q <= 100) {
vector<string> states = {S};
while (Q--) {
string T;
cin >> T;
if (T == "toggle") {
int P;
cin >> P;
P--;
S[P] ^= 1;
} else {
int L, R;
cin >> L >> R;
L--, R--;
int ans = 0;
for (auto value : states) {
ans += value.substr(L, R - L) == string(R - L, '1');
}
cout << ans << "\n";
}
states.push_back(S);
}
} else {
vector<int> sum(N), last(N), par(N);
for (int i = 0; i < N; i++) {
par[i] = S[i] - '0';
}
for (int i = 1; i <= Q; i++) {
string T;
cin >> T;
if (T == "toggle") {
int P;
cin >> P;
P--;
if (par[P] == 1) {
sum[P] += i - last[P];
last[P] = i;
}
par[P] ^= 1;
} else {
int L, R;
cin >> L >> R;
L--, R--;
int ans = sum[L];
if (par[L] == 1) {
ans += i - last[L];
}
cout << ans << "\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
52 ms |
1364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |