#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 24211007;
const ll infll = 1e18 + 7;
const int base = 200;
const int LOG = 29;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int q;
string s;
void solve()
{
cin >> n;
cin >> s;
cin >> q;
while(q--) {
int l, r;
cin >> l >> r;
int cur = 0;
int res = 0;
int tmp = 0;
for(int i = l; i <= r; i++) {
if(s[i - 1] == 'C') ++cur;
else --cur;
if(cur < 0) {
cur = 0;
++tmp;
}
}
res = tmp;
tmp = 0;
cur = 0;
for(int i = r; i >= l; i--) {
if(s[i - 1] == 'C') ++cur;
else --cur;
if(cur < 0) {
++cur;
++tmp;
}
}
maximize(res, tmp);
cout << res << endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(TASK".in" , "r" , stdin);
//freopen(TASK".out" , "w" , stdout);
int tc = 1;
// cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |