#include <iostream>
#include <fstream>
using namespace std;
const int nmax=100005;
string str;
int s[nmax],l[nmax],r[nmax];
int n,i,m,st,dr,ans,j,p,take,p1,p2,u1,u2;
int sum(int l,int r)
{
if(l>r) return 0;
return s[r]-s[l-1];
}
int main()
{
// freopen("data.in","r",stdin);
cin>>n;
cin>>str;
cin>>m;
for(int cnt=1;cnt<=m;cnt++)
{
cin>>st>>dr;ans=0;
p1=p2=1;u1=u2=0;
for(j=st;j<=dr;j++)
if(str[j-1]=='C')
l[++u1]=j;
for(j=st;j<=dr;j++)
if(str[j-1]=='C')
r[++u2]=j;
for(j=st;j<=dr;j++)
if(str[j-1]=='T')
{
while(p2<=u2&&r[p2]<j) p2++;
if(p1<=u1&&l[p1]<j&&p2<=u2)
{
p1++;p2++;
}
else
ans++;
}
cout<<ans<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
248 KB |
Output is correct |
2 |
Correct |
25 ms |
356 KB |
Output is correct |
3 |
Correct |
24 ms |
448 KB |
Output is correct |
4 |
Correct |
22 ms |
496 KB |
Output is correct |
5 |
Correct |
20 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
248 KB |
Output is correct |
2 |
Correct |
25 ms |
356 KB |
Output is correct |
3 |
Correct |
24 ms |
448 KB |
Output is correct |
4 |
Correct |
22 ms |
496 KB |
Output is correct |
5 |
Correct |
20 ms |
548 KB |
Output is correct |
6 |
Execution timed out |
3042 ms |
1420 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
248 KB |
Output is correct |
2 |
Correct |
25 ms |
356 KB |
Output is correct |
3 |
Correct |
24 ms |
448 KB |
Output is correct |
4 |
Correct |
22 ms |
496 KB |
Output is correct |
5 |
Correct |
20 ms |
548 KB |
Output is correct |
6 |
Execution timed out |
3042 ms |
1420 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |