Submission #581370

#TimeUsernameProblemLanguageResultExecution timeMemory
581370willi19Election (BOI18_election)C++17
28 / 100
3074 ms1108 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; //1 => l-1~r ll n,q; string s; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin>>n; cin>>s; cin>>q; while(q--) { ll l,r; cin>>l>>r; vector<char> lf; ll cnt = 0,ans = 0; for(ll i=l-1;i<r;i++) { if(s[i]=='T'&&cnt==0) ans++; else { if(s[i]=='T') cnt--; else cnt++; lf.push_back(s[i]); } } reverse(lf.begin(),lf.end()); cnt = 0; for(char c:lf) { if(c=='T'&&cnt==0) ans++; else { if(c=='T') cnt--; else cnt++; } } cout<<ans<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...