Submission #1267673

#TimeUsernameProblemLanguageResultExecution timeMemory
1267673AlebnElection (BOI18_election)C++20
0 / 100
8 ms320 KiB
#include <bits/stdc++.h> #define int long long #define pii pair<int,int> #define ff first #define ss second #define all(x) x.begin(),x.end() using namespace std; signed main() { int n, q, x, y, temp, ma, mai; string s; cin >> n >> s; vector<int> a(n), pref(n); for(int i = 0; i < n; i++) { if(s[i] == 'C') a[i] = 1; else a[i] = -1; pref[i] = a[i] + (i ? pref[i - 1] : 0); } function<int(int,int)> sum = [&](int l, int r) { return pref[r] - (l ? pref[l - 1] : 0); }; cin >> q; while(q--) { cin >> x >> y; x--, y--; temp = LLONG_MAX, ma = LLONG_MIN, mai = LLONG_MIN; for(int i = x; i <= y; i++) { temp = min(temp, sum(x, i)); ma = max(ma, sum(x, i) - temp); mai = max(mai, sum(x, i)); } cout << max(mai - sum(x, y), max(ma - sum(x, y), abs(temp))) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...