# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759430 | Bula | Election (BOI18_election) | C++17 | 4 ms | 372 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
string s;
cin>>s;
vector<int> v(n+1),pref(n+1),suf(n+2);
for(int i=1;i<=n;i++){
if(s[i-1]=='T') v[i]=1;
else v[i]=-1;
}
for(int i=1;i<=n;i++){
pref[i]=pref[i-1]+v[i];
}
for(int i=n;i>=1;i--){
suf[i]=suf[i+1]+v[i];
}
int q;
cin>>q;
for(int i=0;i<q;i++){
int l,r;
cin>>l>>r;
int ans=0;
for(int j=l;j<=r;j++){
ans=max(ans,max(pref[j]-pref[l-1],suf[j]-suf[r+1]));
}
cout<<ans<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |