Submission #638820

#TimeUsernameProblemLanguageResultExecution timeMemory
638820georgievskiyElection (BOI18_election)C++17
28 / 100
3068 ms1444 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; vector<int> c(n, 0); int q; cin >> q; while (q--) { int l, r; cin >> l >> r; l--; fill(c.begin() + l, c.begin() + r, 0); int b = 0; for (int i = l; i < r; i++) { if (s[i] == 'C') { b++; } else { b--; if (b < 0) { b = 0; c[i] = 1; } } } b = 0; for (int i = r - 1; i >= l; i--) { if (s[i] == 'C') { b++; } else if (!c[i]) { b--; if (b < 0) { b = 0; c[i] = 1; } } } int ans = count(c.begin() + l, c.begin() + r, 1); cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...