#ifdef DEBUG
#include "debug.hpp"
#else
#pragma GCC optimize("Ofast")
#define trace(...)
#include <bits/stdc++.h>
#define endl '\n'
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
string s;
cin >> n >> s;
vector<int> v(n);
transform(s.begin(), s.end(), v.begin(),
[](char c) { return c == 'C' ? 1 : -1; });
vector<int> pref(n + 1), suff(n + 1);
partial_sum(v.begin(), v.end(), pref.begin() + 1);
partial_sum(v.rbegin(), v.rend(), suff.rbegin() + 1);
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
--l, --r;
int ans = 0;
{
int mn = INT_MAX;
for (int i = l; i <= r; ++i) {
mn = min(mn, pref[i + 1]);
}
ans = min(ans, mn - pref[l]);
}
{
int mn = INT_MAX;
for (int i = l; i <= r; ++i) {
mn = min(mn, suff[i]);
}
ans = min(ans, mn - suff[r + 1]);
}
ans = -ans;
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |