Submission #852911

#TimeUsernameProblemLanguageResultExecution timeMemory
852911AbitoElection (BOI18_election)C++14
0 / 100
1 ms4952 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt //#define int long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=1e5+5; int n,q,a[N],st[25][N],lg[N],p[N],ans[N],l[N],r[N]; void build(){ for (int i=1;i<=n;i++) st[0][i]=p[i]; for (int i=1;i<25;i++){ for (int j=1;j+(1<<i)<=n+1;j++){ st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]); } }return; } int query(int l,int r){ int i=lg[r-l+1]; return min(st[i][l],st[i][r-(1<<i)+1]); } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); for (int i=2;i<N;i++) lg[i]=lg[i/2]+1; cin>>n; for (int i=1;i<=n;i++){ char c;cin>>c; if (c=='C') a[i]=1; else a[i]=-1; p[i]=a[i]+p[i-1]; }build(); cin>>q; for (int i=1;i<=q;i++){ cin>>l[i]>>r[i]; ans[i]=max(0,-(query(l[i],r[i])-p[l[i]-1])); } for (int i=n;i;i--) p[i]=p[i+1]+a[i]; build(); for (int i=1;i<=q;i++) ans[i]=max(ans[i],max(0,-(query(l[i],r[i])-p[r[i]+1]))); for (int i=1;i<=q;i++) cout<<ans[i]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...