#include <bits/stdc++.h>
using namespace std;
#define ar array< int , 2>
#define MASK(i) (1 << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
const int MAX = 1e6 + 1000;
int n, k, x, y;
char c;
map< char , int > d[MAX];
string s;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> s;
for (int i = 1; i <= n; i++)
{
c = s[i - 1];
if (c == 'C')
{
d[i]['C'] = d[i - 1]['C'] + 1;
d[i]['T'] = d[i - 1]['T'];
}
else
{
d[i]['T'] = d[i - 1]['T'] + 1;
d[i]['C'] = d[i - 1]['C'];
}
}
cin >> k;
for (int i = 1; i <= k; i++)
{
cin >> x >> y;
//cout << d[y]['C'] - d[x - 1]['C'] << '\n' ;
int ans = 0;
for (int j = x; j <= y; j++)
{
ans = max(ans, d[j]['T'] - d[x - 1]['T'] - d[j]['C'] + d[x - 1]['T']);
}
for (int j = y; j >= x; j--)
{
ans = max(ans, d[y]['T'] - d[j - 1]['T'] - d[y]['C'] + d[j - 1]['C']);
}
cout << ans << '\n' ;
}
}
/*
11
CCCTTTTTTCC
3
1 11
4 9
1 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
47508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
47508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
47508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |