Submission #859372

#TimeUsernameProblemLanguageResultExecution timeMemory
8593721075508020060209tcElection (BOI18_election)C++14
28 / 100
3026 ms6400 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void solve(vector<int>ar){ int n=ar.size()-1; vector<int>br=ar; priority_queue<int>pq; int tot=0; int ret=0; for(int i=1;i<=n;i++){ tot+=ar[i]; if(tot<0){ tot+=1;br[i]=0;ret++; } } tot=0; for(int i=n;i>=1;i--){ tot+=br[i]; if(tot<0){ tot+=1;br[i]=0;ret++; } } cout<<ret<<endl; } int n;int Q; int ar[500005]; signed main(){ cin>>n; { string s; cin>>s; for(int i=0;i<n;i++){ if(s[i]=='C'){ ar[i+1]=1; }else{ ar[i+1]=-1; } } } cin>>Q; while(Q--){ int l;int r; cin>>l>>r; vector<int>vc; vc.push_back(0); for(int i=l;i<=r;i++){ vc.push_back(ar[i]); } solve(vc); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...