#include <bits/stdc++.h>
using namespace std;
const long long MX=500002;
string s;
int n,q;
int masnm[MX];
void zap(int l,int r,int nmzp)
{
int zrsum=0,kop=0;
for(int i=l;i<=r;i++)
{
if(s[i]=='C')
{
zrsum++;
}
else
{
if(zrsum==0)
{
masnm[i]=nmzp;
kop++;
}
else
{
zrsum--;
}
}
}
zrsum=0;
for(int i=r;i>=l;i--)
{
if(s[i]=='C')
{
zrsum++;
}
else
{
if(masnm[i]!=nmzp)
{
if(zrsum==0)
{
kop++;
}
else
{
zrsum--;
}
}
}
}
cout<<kop<<"\n";
return;
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>s>>q;
s="*"+s;
for(int i=1;i<=q;i++)
{
int l,r;
cin>>l>>r;
zap(l,r,i);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3075 ms |
1448 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3075 ms |
1448 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |