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;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
bool valid(string s, int a, int b)
{
//cout<<s<<' '<<a<<' '<<b<<'\n';
FOR(i,a,b)
{
if(s[i]=='0')return 0;
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n,q;
cin>>n>>q;
string s;
cin>>s;
vpi qs;
F0R(p,q)
{
string t;
cin>>t;
if(t=="toggle")
{
int i;
cin>>i;
qs.pb({i-1,-1});
}
else
{
int a,b;
cin>>a>>b;
--a;--b;
qs.pb({a,b});
}
}
F0R(i,q)
{
if(qs[i].se==-1)continue;
int a=qs[i].fi;
int b=qs[i].se;
int ans=0;
string road=s;
F0R(j,i+1)
{
if(valid(road,a,b))++ans;
if(qs[j].se==-1)road[qs[j].fi]=(!(road[qs[j].fi]-'0'))+'0';
}
cout<<ans<<'\n';
}
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... |