Topic Link: D. Inna and Sequence
Test instructions: Three operations, 1 to the sequence after adding a 1,0 to the sequence after adding a 0,-1, the number of the given position is deleted.
Puzzle: The number of saved in a tree array is not deleted, the location is found every two minutes, and then the array tag is deleted here.
#include <bits/stdc++.h>#include<Set>#include<iostream>#include<string>#include<cstring>#include<algorithm>#definePB Push_back#definell Long Long#definePI 3.14159265#defineLS l,m,rt<<1#defineRS M+1,r,rt<<1|1#defineEPS 1e-7typedef unsignedLong Longull;Const intmod=1e9+9;Const intinf=0x3f3f3f3f;Const intmaxn=1e6+5;Const introot=1e6+7;using namespacestd;ll T,n,m,k,len;inttot,ed;intA[MAXN],B[MAXN],V[MAXN];intP[maxn];vector<int>St;intLowbit (intx) { returnx& (-x);}voidAddintXinty) { for(inti=x;i<maxn;i+=lowbit (i)) {B[i]+=y; }}intGet_sum (intx) { intans=0; while(x>0) {ans+=B[x]; X-=lowbit (x); } returnans;}intSecintx) { intL=1, r=Ed; while(l<=r) {intMid= (l+r) >>1; if(Get_sum (mid) >=x) r=mid-1; ElseL=mid+1; } returnl;}voidview () { for(intI=1; i<=ed;i++) { if(!v[i]) cout<<A[i]; } cout<<Endl;}intMain () {Ios::sync_with_stdio (false); Cin.tie (0); CIN>>n>>m; for(intI=0; i<m;i++) {cin>>P[i]; } intop; while(n--) {cin>>op; if(op==1) { ++tot; a[++ed]=1; Add (Ed,1); } Else if(op==0) { ++tot; ++Ed; Add (Ed,1); } Else { if(tot<=0)Continue; intPp=lower_bound (P,p+m,tot)-p; if(P[pp]==tot) pp++; for(intI=0; i<pp;i++) { intL=sec (P[i]); ST.PB (l); Tot--; V[L]=true; } for(intI=0; I<st.size (); i++) {Add (St[i],-1); } st.clear (); } //view (); } if(tot>0) {view (); } Else{cout<<"Poor stack!"<<Endl; } return 0;}
Codeforces Round #220 (Div. 2) D. Inna and Sequence tree array + dichotomy