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>
#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 |
---|
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |