Submission #565572

#TimeUsernameProblemLanguageResultExecution timeMemory
565572MajidElection (BOI18_election)C++17
28 / 100
3077 ms2444 KiB
#include<bits/stdc++.h> using namespace std; //Types using ll = long long; using db = double; //Vectors #define pb push_back #define sz(vec) ((ll)vec.size()) #define all(vec) vec.begin(), vec.end() //things #define f first #define s second const int SMALLINF = 1e9 + 7; const ll BIGINF = ((ll)1e18) + 7; #define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL); void solve(){ ll n, q; string s; cin>>n>>s>>q; while(q--){ ll l, r, cntc = 0, cnte = 0, ans = 0; map<ll, bool> mark; cin>>l>>r; l--, r--; for(ll i = l; i <= r; i++){ if(s[i]=='C')cntc++; else if(!mark[i])cnte++; if(cnte>cntc){ if(!mark[i]){ cnte--; mark[i] = true; ans++; } } } cntc = 0, cnte = 0; for(ll i = r; i >= l; i--){ if(s[i]=='C')cntc++; else if(!mark[i])cnte++; if(cnte>cntc){ if(!mark[i]){ cnte--; mark[i] = true; ans++; } } } cout<<ans<<"\n"; } } int main(){ Speeed ll t=1; // cin>>t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...