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 int long long
#define endl '\n'
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
int pref[200001],sub[200001];
signed main() {
int n,q; cin >> n >> q;
string a; cin >> a;
for(int i = 0; i < n; i++){
if(a[i] == '1') pref[i]++;
if(i) pref[i] += pref[i - 1];
sub[i] = pref[i];
}
vector<pair<string,pair<int,int>>>qw(q);
for(int i = 0; i < q; i++){
cin >> qw[i].first >> qw[i].second.first;
if(qw[i].first != "toggle") cin >> qw[i].second.second;
else qw[i].second.second = 0;
int a = qw[i].second.first - 1, b = qw[i].second.second - 1;
if(qw[i].first == "query"){
int ans = 0;
for(int j = 0; j <= i; j++){
if(qw[j].first == "query"){
if(sub[b - 1] - (a == 0 ? 0 : sub[a - 1]) == (b - a)) ans++;
}else{
if(sub[b - 1] - (a == 0 ? 0 : sub[a - 1]) == (b - a)) ans++;
int c = qw[j].second.first - 1;
if(sub[c] - (c == 0 ? 0 : sub[c - 1]) == 1){
for(int k = c; k < n; k++) sub[k]--;
}else{
for(int k = c; k < n; k++) sub[k]++;
}
}
}
cout << ans << endl;
for(int j = 0; j < n; j++){
sub[j] = pref[j];
}
}
}
return 0;
}
# | 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... |