Submission #802306

#TimeUsernameProblemLanguageResultExecution timeMemory
802306borisAngelovElection (BOI18_election)C++17
28 / 100
3059 ms1012 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 500005; int n; string s; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> s; s = '#' + s; int q; cin >> q; while (q--) { int l, r; cin >> l >> r; vector<bool> gone(n + 5, false); int c = 0; int t = 0; for (int i = l; i <= r; ++i) { if (s[i] == 'C') { c++; } else { if (t + 1 <= c) { ++t; } else { gone[i] = true; } } } c = 0; t = 0; for (int i = r; i >= l; --i) { if (s[i] == 'C') { ++c; } else if (gone[i] == false) { if (t + 1 <= c) { ++t; } else { gone[i] = true; } } } int ans = 0; for (int i = l; i <= r; ++i) { ans += gone[i]; } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...