Submission #1018321

#TimeUsernameProblemLanguageResultExecution timeMemory
1018321YassirSalamaElection (BOI18_election)C++17
0 / 100
4 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]; 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=1e18; int d=1e18; for(int i=l;i<=r;i++){ c=min(c,pref[i]); } for(int i=l;i<=r;i++){ d=min(d,suff[i]); } if(l){ c-=pref[l-1]; } if(r+1<n) d-=suff[r+1]; 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...