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 s;
cin>>s;
int pre[n+1],ans[n][n+1]={};
pre[0]=0;
for (int i=0;i<n;i++)
pre[i+1]=pre[i]+(s[i]-'0');
for (int i=0;i<n;i++)
for (int j=i+1;j<=n;j++)
ans[i][j]=(pre[j]-pre[i]==j-i);
while (q--)
{
string t;
cin>>t;
if (t=="query")
{
int a,b;
cin>>a>>b;
cout<<ans[a-1][b-1]<<endl;
}
else
{
int i;
cin>>i;
s[i-1]=char('0'+1-(s[i-1]-'0'));
}
pre[0]=0;
for (int i=0;i<n;i++)
pre[i+1]=pre[i]+(s[i]-'0');
for (int i=0;i<n;i++)
for (int j=i+1;j<=n;j++)
ans[i][j]+=(pre[j]-pre[i]==j-i);
}
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... |