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>
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];
par[P] ^= 1;
last[P] = i;
}
} 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 |
---|
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... |