Submission #101787

#TimeUsernameProblemLanguageResultExecution timeMemory
101787tushar_2658Election (BOI18_election)C++14
0 / 100
12 ms384 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 7e4 + 5; int arr[maxn], arr1[maxn], arr2[maxn]; string s; int get(int l, int r){ arr1[l] = arr[l]; int mini = arr1[l]; for(int i=l+1; i<=r; i++){ arr1[i] = 0; arr1[i] = arr[i] + arr1[i-1]; mini = min(mini, arr1[i]); } arr2[r] = arr[r]; mini = min(mini, arr2[r]); for(int i=r-1; i>=l; i--){ arr2[i] = 0; arr2[i] = arr[i] + arr2[i+1]; mini = min(mini, arr2[i]); }return mini; } int main(){ //freopen("in.txt", "r", stdin); int n; cin>>n; cin>>s; for(int i=0; i<n; i++){ if(s[i] == 'C')arr[i] = 1; else arr[i] = -1; } int q; cin>>q; while(q--){ int l, r; cin>>l>>r; cout<<abs(get(l-1, r-1))<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...