Submission #855857

#TimeUsernameProblemLanguageResultExecution timeMemory
855857NeroZeinElection (BOI18_election)C++17
28 / 100
3081 ms2532 KiB
#include "bits/stdc++.h" #define int long long using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { char c; cin >> c; a[i] = (c == 'C' ? 1 : -1); } int q; cin >> q; auto solve = [&](int l, int r) { vector<int> nullified(n); int sum = 0; for (int i = l; i <= r; ++i) { if (sum + a[i] < 0) nullified[i] = 1; else sum += a[i]; } sum = 0; for (int i = r; i >= l; --i) { if (nullified[i]) continue; if (sum + a[i] < 0) nullified[i] = 1; else sum += a[i]; } return accumulate(nullified.begin(), nullified.end(), 0); }; while (q--) { int l, r; cin >> l >> r; cout << solve(l - 1, r - 1) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...