Submission #1018326

#TimeUsernameProblemLanguageResultExecution timeMemory
1018326YassirSalamaElection (BOI18_election)C++17
0 / 100
4 ms344 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]-(r+1<n?suff[r+1]:0LL)); } // cout<<c<<" "<<d<<endl; int x=max(-c,-d); ans=max(ans,x); cout<<x<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...