Submission #565606

#TimeUsernameProblemLanguageResultExecution timeMemory
565606AbdullahMWElection (BOI18_election)C++17
28 / 100
3052 ms2064 KiB
#include <bits/stdc++.h> #define all(vec) vec.begin(), vec.end() #define ll long long #define db double #define pb push_back #define pf push_front #define newl "\n" #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define f first #define s second #define MOD 1000000007 using namespace std; int main() { fast //setIO(""); //freopen("filename.in", "r", stdin); //freopen("filename.out", "w", stdout); ll n; cin >> n; string s; cin >> s; ll q; cin >> q; while (q--) { unordered_map <ll, bool> nul; ll l, r; cin >> l >> r; l--, r--; ll c = 0, t = 0, cnt = 0; for (ll i = l; i <= r; i++) { if (s[i] == 'C') c++; else { t++; if (t > c) { nul[i] = true; t--; cnt++; } } } c = 0, t = 0; for (ll i = r; i >= l; i--) { if (s[i] == 'C') c++; else { t++; if (t > c) { t--; if (!nul[i]) cnt++; } else if (nul[i]) t--; } } cout << cnt << newl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...