#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;
bool vis[mxN];
void solve()
{
cin >> n;
cin >> s;
cin >> q;
while(q--) {
int l, r;
cin >> l >> r;
for(int i = l; i <= r; i++) vis[i] = false;
int cur = 0;
int tmp = 0;
for(int i = l; i <= r; i++) {
if(s[i - 1] == 'C') ++cur;
else --cur;
if(cur < 0) {
if(vis[i] == false) {
++tmp;
vis[i] = true;
}
cur = 0;
}
}
cur = 0;
for(int i = r; i >= l; i--) {
if(vis[i] == true) continue;
if(s[i - 1] == 'C') ++cur;
else --cur;
if(cur < 0) {
if(vis[i] == false) {
vis[i] = true;
++tmp;
}
++cur;
}
}
cout << tmp << 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 |
Correct |
6 ms |
328 KB |
Output is correct |
2 |
Correct |
7 ms |
356 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
328 KB |
Output is correct |
2 |
Correct |
7 ms |
356 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3070 ms |
1132 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
328 KB |
Output is correct |
2 |
Correct |
7 ms |
356 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3070 ms |
1132 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |