Submission #565569

#TimeUsernameProblemLanguageResultExecution timeMemory
565569MrDebooElection (BOI18_election)C++17
28 / 100
3063 ms780 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #define int long long #define endl '\n' using namespace std; using namespace __gnu_pbds; using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,q; cin>>n; string s; cin>>s; vector<bool>v(n); for(int i=0;i<n;i++)v[i]=(s[i]=='C'); vector<bool>V(n); cin>>q; while(q--){ int l,r; cin>>l>>r; l--;r--; int cur=0,ans=0; for(int i=l;i<=r;i++){ V[i]=0; cur+=(v[i]?1:-1); if(cur<0){ ans++; V[i]=1; cur=0; } } cur=0; for(int i=r;i>=l;i--){ if(V[i])continue; cur+=(v[i]?1:-1); if(cur<0){ ans++; V[i]=1; cur=0; } } cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...