Submission #111102

#TimeUsernameProblemLanguageResultExecution timeMemory
111102losmi247Election (BOI18_election)C++14
28 / 100
3030 ms2284 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e5+23; int a[N],n; bool ode[N]; string s; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int q; cin >> n; cin >> s; for(int i = 1; i <= n; i++){ a[i] = (s[i-1] == 'C' ? 1 : -1); } cin >> q; while(q--){ int l,r; cin >> l >> r; int sol = 0,bal = 0; for(int i = l; i <= r; i++){ ode[i] = 0; } for(int i = l; i <= r; i++){ bal += a[i]; if(bal < 0){ ode[i] = 1; sol++; bal++; } } bal = 0; for(int i = r; i >= l; i--){ if(ode[i]){ continue; } bal += a[i]; if(bal < 0){ sol++; bal++; } } cout << sol << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...