Submission #173557

#TimeUsernameProblemLanguageResultExecution timeMemory
173557nikolapesic2802Election (BOI18_election)C++14
28 / 100
3045 ms38428 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define f first #define s second #define all(x) x.begin(), x.end() #define D(x) cerr << #x << " is " << (x) << "\n"; using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key() template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;} template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;} template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} const int N=5e5+5; vector<pair<int,int> > mxpre(4*N),mxsuf(4*N); vector<int> prearr(N),sufarr(N),cnt(N); void initpre(int l=0,int r=N-1,int i=1){ if(l==r){ mxpre[i]={prearr[l],N-l}; return; } int m=(l+r)>>1; initpre(l,m,2*i); initpre(m+1,r,2*i+1); mxpre[i]=max(mxpre[2*i],mxpre[2*i+1]); } pair<int,int> getpre(int qs,int qe,int l=0,int r=N-1,int i=1){ if(qs>r||qe<l) return {INT_MIN,INT_MIN}; if(qs<=l&&qe>=r) return mxpre[i]; int m=(l+r)>>1; return max(getpre(qs,qe,l,m,2*i),getpre(qs,qe,m+1,r,2*i+1)); } void initsuf(int l=0,int r=N-1,int i=1){ if(l==r){ mxsuf[i]={sufarr[l],l}; return; } int m=(l+r)>>1; initsuf(l,m,2*i); initsuf(m+1,r,2*i+1); mxsuf[i]=max(mxsuf[2*i],mxsuf[2*i+1]); } pair<int,int> getsuf(int qs,int qe,int l=0,int r=N-1,int i=1){ if(qs>r||qe<l) return {INT_MIN,INT_MIN}; if(qs<=l&&qe>=r) return mxsuf[i]; int m=(l+r)>>1; return max(getsuf(qs,qe,l,m,2*i),getsuf(qs,qe,m+1,r,2*i+1)); } int get(int l,int r){ if(l>r) return 0; int ans=cnt[r]; if(l) ans-=cnt[l-1]; return ans; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n,q; string s; cin >> n >> s >> q; string t=s; for(int i=0;i<q;i++){ int l,r; cin >> l >> r; l--;r--; int ans=0,sum=0; for(int j=l;j<=r;j++){ if(t[j]=='C') sum++; if(t[j]=='T') sum--; if(sum<0) sum++,t[j]='X',ans++; } sum=0; for(int j=r;j>=l;j--){ if(t[j]=='C') sum++; if(t[j]=='T') sum--; if(sum<0) sum++,t[j]='X',ans++; } for(int j=l;j<=r;j++) t[j]=s[j]; printf("%i\n",ans); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...