Submission #528818

#TimeUsernameProblemLanguageResultExecution timeMemory
528818andrei_boacaElection (BOI18_election)C++17
28 / 100
3080 ms15376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; int n,q; string ss; int v[500005]; vector<pii> qr[500005]; bool use[500005]; int sol[500005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; cin>>ss; for(int i=0;i<n;i++) { if(ss[i]=='C') v[i+1]=1; else v[i+1]=-1; } cin>>q; for(int i=1;i<=q;i++) { int l,r; cin>>l>>r; qr[l].push_back({r,i}); } deque<int> coada; for(int i=n;i>=1;i--) { if(v[i]==-1) { coada.push_front(i); use[i]=1; } else { //update(1,1,n,1,i,1); if(!coada.empty()) { int poz=coada.front(); use[poz]=0; //update(1,1,n,1,poz,-1); coada.pop_front(); } } for(auto j:qr[i]) { int poz=j.first,index=j.second; int minim=1e9,suma=0; int rez=0; for(int k=poz;k>=i;k--) { suma+=(!use[k])*v[k]; minim=min(minim,suma); if(use[k]) rez++; } if(minim<0) rez+=abs(minim); sol[index]=rez; } } for(int i=1;i<=q;i++) cout<<sol[i]<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...