| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1367126 | matthew | Election (BOI18_election) | C++20 | 1 ms | 344 KiB |
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
using ll = long long;
const int MAX_N = 500'000;
const int INF = 1e9;
char a[MAX_N];
int s[MAX_N + 1];
char next_char() {
char ch;
while(isspace(ch = fgetc(stdin)));
return ch;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
a[i] = next_char();
}
s[0] = 0;
for(int i = 1; i <= n; i++) {
s[i] = s[i - 1] + (a[i - 1] == 'C' ? 1 : -1);
}
int q;
scanf("%d", &q);
for(int i = 0; i < q; i++) {
int l, r;
scanf("%d%d", &l, &r);
int min = INF;
int max = -INF;
for(int j = l; j <= r; j++) {
min = std::min(min, s[j]);
max = std::max(max, s[j]);
}
min -= s[l - 1];
max -= s[l - 1];
printf("%d\n", std::max(0, std::max(-min, max - s[r])));
}
return 0;
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
