Submission #128222

#TimeUsernameProblemLanguageResultExecution timeMemory
128222thanosElection (BOI18_election)C++14
0 / 100
28 ms504 KiB
#include<iostream> #include<string> #include<cstdio> using namespace std; struct query{ int l; int r; }q[500005]; string A; int main(){ //freopen("1-elections.in","r",stdin); int N; cin>>N; cin>>A; int K; cin>>K; for(int i=0; i<K; i++){ cin>>q[i].l>>q[i].r; } for(int d=0; d<K; d++){ bool v[100005]={false}; int sum=0,cnt=0; for(int i=q[d].l; i<=q[d].r; i++){ if(A[i-1]=='C'){ sum--; } else{ sum++; } if(sum>0 && A[i-1]=='T'){ cnt++; v[i]=true; sum--; } } sum=0; for(int i=q[d].r; i>=q[d].l; i--){ if(A[i-1]=='C'){ sum--; } else{ sum++; } if(sum>0 && !v[i] && A[i-1]=='T'){ cnt++; } if(v[i]) sum--; } cout<<cnt<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...