# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361974 | kshitij_sodani | Election (BOI18_election) | C++14 | 3090 ms | 2912 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.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
int n;
int it[500001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
string s;
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='T'){
it[i]=-1;
}
else{
it[i]=1;
}
//cout<<it[i]<<",";
}
//cout<<endl;
int q;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--;
r--;
int su=0;
vector<int> kk;
for(int i=l;i<=r;i++){
kk.pb(it[i]);
}
/* for(auto j:kk){
cout<<j<<",";
}
cout<<endl;*/
int ans=0;
for(int i=0;i<kk.size();i++){
su+=kk[i];
if(su<0){
su-=kk[i];
kk[i]=0;
// su+=kk[i];
ans++;
}
}
su=0;
for(int i=kk.size()-1;i>=0;i--){
su+=kk[i];
if(su<0){
su-=kk[i];
kk[i]=0;
// su+=kk[i];
ans++;
}
}
/* for(auto j:kk){
cout<<j<<",";
}
cout<<endl;*/
cout<<ans<<endl;
}
return 0;
}
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... |