제출 #530350

#제출 시각아이디문제언어결과실행 시간메모리
530350Koosha_mvElection (BOI18_election)C++14
0 / 100
9 ms12108 KiB
#include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=5e5+99; int n,q,a[N],ans[N],seg[N<<2],lazy[N<<2]; vector<int> vec; vector<pair<int,int>> Q[N]; string s; void shift(int id){ seg[id<<1]+=lazy[id]; seg[id<<1|1]+=lazy[id]; lazy[id<<1]+=lazy[id]; lazy[id<<1|1]+=lazy[id]; lazy[id]=0; } void build(int id=1,int l=1,int r=n+1){ if(l+1==r){ seg[id]=a[l]; return ; } int mid=(l+r)>>1; build(id<<1,l,mid); build(id<<1|1,mid,r); } void add(int L,int R,int val,int id=1,int l=1,int r=n+1){ if(r<=L || R<=l) return ; if(L<=l && r<=R){ seg[id]+=val; lazy[id]+=val; return ; } int mid=(l+r)>>1; shift(id); add(L,R,val,id<<1,l,mid); add(L,R,val,id<<1|1,mid,r); } int get(int L,int R,int id=1,int l=1,int r=n+1){ if(r<=L || R<=l) return N; if(L<=l && r<=R){ return seg[id]; } int mid=(l+r)>>1; return min(get(L,R,id<<1,l,mid),get(L,R,id<<1|1,mid,r)); } int main(){ ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); cin>>n>>s>>q; s=' '+s; f(i,1,q+1){ int l,r; cin>>l>>r; Q[r].pb(mp(l,i)); } f(i,1,n+1){ a[i]=a[i-1]+(s[i]=='C'); } f(i,1,n+1){ if(s[i]=='C'){ if(vec.size()){ add(vec.back(),n+1,-1); vec.pop_back(); } } else{ vec.pb(i); add(i,n+1,+1); } //dbgv(vec); for(auto p : Q[i]){ int t=0; if(p.F-1) t=get(p.F-1,p.F); ans[p.S]=max(0,t-get(p.F,i+1)); int l=-1,r=vec.size(); while(l+1<r){ int mid=(l+r)>>1; if(vec[mid]<p.F){ l=mid; } else{ r=mid; } } //cout<<p.S<<" "<<r<<endl; ans[p.S]+=vec.size()-r; } } f(i,1,q+1){ cout<<ans[i]<<" "; } } /* 11 CCCTTTTTTCC 1 4 9 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...