Question Surface
Hall Theorem in Board Discussion
Hall theorem: a bipartite graph has a perfect matching condition. For any $ I $ left vertex, there are at least $ I $ right vertex adjacent to them. Put it in this question, that is, it is obvious that the case that the shoes are not enough is a continuous person, so we can maintain the maximum sub-section and just like =. =
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=200005; 6 long long ll[4*N],rr[4*N],len[4*N],val[4*N]; 7 long long n,m,k,d,t1,t2; 8 void pushup(int nde) 9 {10 int ls=2*nde,rs=2*nde+1;11 ll[nde]=max(val[ls]+ll[rs],ll[ls]);12 rr[nde]=max(val[rs]+rr[ls],rr[rs]);13 len[nde]=max(max(len[ls],len[rs]),rr[ls]+ll[rs]);14 val[nde]=val[ls]+val[rs];15 }16 void create(int nde,int l,int r)17 {18 if(l==r) 19 ll[nde]=rr[nde]=len[nde]=val[nde]=-k;20 else21 {22 int mid=(l+r)/2,ls=2*nde,rs=2*nde+1;23 create(ls,l,mid),create(rs,mid+1,r);24 pushup(nde);25 }26 }27 void change(int nde,int l,int r,int pos,int task)28 {29 if(l==r) 30 {31 ll[nde]+=task,rr[nde]+=task;32 len[nde]+=task,val[nde]+=task;33 }34 else35 {36 int mid=(l+r)/2,ls=2*nde,rs=2*nde+1;37 if(pos<=mid) change(ls,l,mid,pos,task);38 else change(rs,mid+1,r,pos,task);39 pushup(nde);40 }41 }42 int main ()43 {44 scanf("%lld%lld%lld%lld",&n,&m,&k,&d),create(1,1,n);45 for(int i=1;i<=m;i++)46 {47 scanf("%lld%lld",&t1,&t2),change(1,1,n,t1,t2);48 (len[1]<=k*d)?printf("TAK\n"):printf("NIE\n");49 }50 return 0;51 }52
View code
Solution: poi 2009 lyz