Submission #1018325

#TimeUsernameProblemLanguageResultExecution timeMemory
1018325YassirSalamaElection (BOI18_election)C++17
0 / 100
5 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n; cin>>n; string s; cin>>s; int arr[n]; for(int i=0;i<n;i++){ arr[i]=(s[i]=='C'?1:-1); } int pref[n]; int suff[n+1]; for(int i=0;i<n;i++){ pref[i]=arr[i]; if(i) pref[i]+=pref[i-1]; } for(int j=n-1;j>=0;j--){ suff[j]=arr[j]; if(j+1<n) suff[j]+=suff[j+1]; } int q; cin>>q; while(q--){ int ans=0; int l,r; cin>>l>>r; l--,r--; int c=0; int d=0; for(int i=l;i<=r;i++){ c=min(c,pref[i]-(l?pref[l-1]:0LL)); } for(int i=l;i<=r;i++){ d=min(d,suff[i]-suff[r+1]); } // cout<<c<<" "<<d<<endl; int x=max(-c,-d); ans=max(ans,x); cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...