/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author win11905
*/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 5e5+5;
class election {
private:
int n, m;
char arr[N];
bool st[N];
public:
void solve(istream& cin, ostream& cout) {
cin >> n;
cin >> arr+1;
cin >> m;
for(int i = 0, l, r; i < m; ++i) {
cin >> l >> r;
int cnt = 0;
set<int> s;
for(int i = l; i <= r; ++i) {
cnt += arr[i] == 'C' ? 1 : -1;
if(cnt < 0) s.emplace(i), cnt++;
}
cnt = 0;
for(int i = r; i >= l; --i) {
if(s.count(i)) continue;
cnt += arr[i] == 'C' ? 1 : -1;
if(cnt < 0) s.emplace(i), cnt++;
}
cout << s.size() << endl;
}
}
};
class Solver {
public:
void solve(std::istream& in, std::ostream& out) {
election *obj = new election();
obj->solve(in, out);
}
};
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
Compilation message
election.cpp: In member function 'void election::solve(std::istream&, std::ostream&)':
election.cpp:31:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin >> arr+1;
~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1408 KB |
Output is correct |
2 |
Correct |
22 ms |
1280 KB |
Output is correct |
3 |
Correct |
14 ms |
1408 KB |
Output is correct |
4 |
Correct |
56 ms |
1408 KB |
Output is correct |
5 |
Correct |
41 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1408 KB |
Output is correct |
2 |
Correct |
22 ms |
1280 KB |
Output is correct |
3 |
Correct |
14 ms |
1408 KB |
Output is correct |
4 |
Correct |
56 ms |
1408 KB |
Output is correct |
5 |
Correct |
41 ms |
1408 KB |
Output is correct |
6 |
Execution timed out |
3025 ms |
2040 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1408 KB |
Output is correct |
2 |
Correct |
22 ms |
1280 KB |
Output is correct |
3 |
Correct |
14 ms |
1408 KB |
Output is correct |
4 |
Correct |
56 ms |
1408 KB |
Output is correct |
5 |
Correct |
41 ms |
1408 KB |
Output is correct |
6 |
Execution timed out |
3025 ms |
2040 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |