Submission #637492

#TimeUsernameProblemLanguageResultExecution timeMemory
637492BenmathElection (BOI18_election)C++14
0 / 100
12 ms340 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string s; cin>>s; int q; cin>>q; while(q--){ int l,r; cin>>l>>r; l--; r--; vector<int>v1; vector<int>v2; int ro=0; for(int i=l;i<=r;i++){ if(s[i]=='C'){ if(i!=l and s[i-1]=='T'){ v1.push_back(0-ro); if(ro<0){ ro=0; } } ro++; }else{ ro--; } } if(s[r]=='T'){ v1.push_back(0-ro); } int j=v1.size()-1; ro=0; int ans=0; for(int i=r;i>=l;i--){ if(s[i]=='C'){ if(i!=r and s[i+1]=='T'){ if(ro<0){ ans=ans+max(abs(ro),v1[j]); ro=ro+max(abs(ro),v1[j]); j--; }else if(v1[j]>0){ ans=ans+v1[j]; ro=ro+v1[j]; j--; }else{ j--; } } ro++; }else{ ro--; } } if(s[l]=='T'){ ans=ans+max(abs(ro),v1[j]); } cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...