Submission #789079

#TimeUsernameProblemLanguageResultExecution timeMemory
789079Genius3435Election (BOI18_election)C++17
28 / 100
3063 ms1148 KiB
#pragma GCC optimize "Ofast,unroll-loops" #pragma GCC target "avx,avx2,sse4" #include <bits/stdc++.h> using namespace std; int constexpr N = 1<<19; int upd[N]; char s[N]; int ss[N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n >> s; for (int i = 0; i < n; ++i) ss[i] = s[i] == 'C' ? 1 : -1; int q; cin >> q; for (int qi = 1; qi <= q; ++qi) { int l, r; cin >> l >> r; --l; int ans = 0; for (int i = l, c = 0; i < r; ++i) { c += ss[i]; if (c < 0) ++c, ++ans, upd[i] = qi; } for (int i = r-1, c = 0; i >= l; --i) { c += ss[i] + (upd[i] == qi); if (c < 0) ++c, ++ans; } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...