#include <bits/stdc++.h>
#define nl '\n'
#ifdef LOCAL
#include "template/debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
std::vector<std::string> state(q + 1);
std::cin >> state[0];
std::vector<std::vector<int>> pref(q + 1);
auto make_pref = [&](int id) {
pref[id].resize(n + 1);
pref[id][0] = 0;
for (int i = 0; i < n; i++) {
pref[id][i + 1] = pref[id][i] + (state[id][i] == '1');
}
};
make_pref(0);
for (int tt = 1; tt <= q; tt++) {
std::string com;
std::cin >> com;
state[tt] = state[tt - 1];
if (com == "toggle") {
int i;
std::cin >> i;
--i;
state[tt][i] = '1' ^ '0' ^ state[tt][i];
} else {
int a, b;
std::cin >> a >> b;
--a, --b;
int ans = 1;
for (int x = 0; x < tt; x++) {
ans += pref[x][b] - pref[x][a] == b - a;
}
std::cout << ans << nl;
}
dbg(state[tt]);
make_pref(tt);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5081 ms |
48288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |