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(){
int n,q;
cin>>n>>q;
string st;
cin>>st;
if (n<=100&&q<=100){
vector <string> v;
v.push_back(st);
for (int z=1; z<=q; z++){
string s;
cin>>s;
if (s=="toggle"){
int u;
cin>>u;
u--;
if (st[u]=='0') st[u]='1';
else st[u]='0';
} else {
int t,u;
cin>>t>>u;
t--;
u--;
int cnt=0;
for (auto&i:v){
bool ok=1;
for (int j=t; j<u; j++){
if (i[j]!='1'){
ok=0;
break;
}
}
if (ok) cnt++;
}
cout<<cnt<<endl;
}
v.push_back(st);
}
} else {
int cnt[n]={},on[n]={};
for (int i=0; i<n; i++){
if (st[i]=='1') on[i]=0;
}
for (int z=1; z<=q; z++){
string s;
cin>>s;
if (s=="toggle"){
int u;
cin>>u;
u--;
if (st[u]=='0'){
st[u]='1';
on[u]=z;
} else {
st[u]='0';
cnt[u]+=z-on[u];
}
} else {
int u,dummy;
cin>>u>>dummy;
u--;
if (st[u]=='0') cout<<cnt[u]<<endl;
else cout<<cnt[u]+z-on[u]<<endl;
}
}
}
}
# | 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... |