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;
const int nx=5e5+5;
int n, v[nx], w[nx], q, l, r, cnt, ans;
string s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>s;
for (int i=1; i<=n; i++) v[i]=s[i-1]=='C';
cin>>q;
while (q--)
{
cin>>l>>r;
cnt=ans=0;
for (int i=l; i<=r; i++)
{
if (v[i]) w[i]=v[i], cnt++;
else if (cnt==0) w[i]=2, ans++;
else w[i]=0, cnt--;
}
cnt=0;
for (int i=r; i>=l; i--)
{
if (w[i]==1) cnt++;
else if (w[i]==2) continue;
else if (w[i]==0&&cnt==0) ans++;
else cnt--;
}
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... |