Submission #861341

#TimeUsernameProblemLanguageResultExecution timeMemory
861341AiperiiiElection (BOI18_election)C++17
28 / 100
3033 ms1576 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n,q; cin>>n; string s; cin>>s; cin>>q; while(q--){ int l,r; cin>>l>>r;l--;r--; int ans=0; vector <int> nu(s.size(),-1); int cnt2=0,cnt1=0; for(int i=l;i<=r;i++){ if(s[i]=='C')cnt1++; else cnt2++; if(cnt2>cnt1){ nu[i]=0; ans++; cnt2--; } } cnt2=0;cnt1=0; for(int i=r;i>=l;i--){ if(s[i]=='C')cnt1++; else if(s[i]=='T' && nu[i]==-1)cnt2++; if(cnt2>cnt1){ nu[i]=0; ans++; cnt2--; } } cout<<ans<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...