hdu5737 (2016 Multi-school League 2nd game D)

Source: Internet
Author: User

Test instructions: to 2 sets of data A and B arrays, each with 2 operations: (+,L,R,X) The A array of the first to the first r elements are all x, (?, l,r) query [l,r] between the location of the a[i]>=b[i] (i>=l && i<= R) and count the number of these locations

have been thinking for a long time, did not think of any effective solutions, until the solution to see it, the original line of tree set balance tree also has this situation: inside is actually not a balance tree, just ordered table.

And then the problem is converted to the number of interval lookups corresponding to the ranking

Since this problem does not have to modify 2 arrays, of which 1 B-tree can be used as a fixed segment tree set ordered table to save time, the other 1 table a tree is simply using a line segment tree method first modified, and then update the corresponding B-tree node ranking

Find rankings here if all LOGN lookups are due to the constant too large direct card, note that each node contains a sequence table and contains a relationship up and down

Then we can update the parent node rank in the B-tree bottom-up corresponding to the ranking of the left and right sub-tree, using the method of merge sorting, Occupy space only O (Nlogn), Time is O (NLOGN)

By the way, a tree that will change the 1 nodes of the B-tree to find out the ranking, the modification of the root node corresponding to the location, and then according to the location of the sub-tree table one side downward update to the sub-tree corresponding position

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<Set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>using namespacestd;typedef __int64 ll;intMaxintAintb) {returnA>b?a:b;}intMinintAintb) {returnA<b?a:b;}intCNT;Const intn=100010, m=262150, e=1768950;intN,m,i,a[n],b[n],x,l,r;intst[m],en[m],v[m],tag[m],pl[e],pr[e],pool[e],cur;ll ans,sum;voidBuildintXintLintR) {Tag[x]=-1; if(l==R) {St[x]=cur+1; pool[++cur]=B[l]; EN[X]=cur; V[X]= (a[l]>=B[l]); return; }    intMid= (l+r) >>1); Build (x<<1, L,mid); Build ((x<<1)|1, mid+1, R); V[X]=v[x<<1]+v[(x<<1)|1]; intal=st[x<<1],ar=en[x<<1],bl=st[(x<<1)|1],br=en[(x<<1)|1]; ST[X]=cur+1;  while(AL&LT;=AR&AMP;&AMP;BL&LT;=BR) pool[++cur]=pool[al]<pool[bl]?pool[al++]:p ool[bl++];  while(Al<=ar) pool[++cur]=pool[al++];  while(BL&LT;=BR) pool[++cur]=pool[bl++]; EN[X]=cur; Al=st[x<<1],bl=st[x<<1|1];  for(inti=st[x];i<=cur;i++)    {         while(Al<=ar&&pool[al]<=pool[i]) al++;  while(Bl<=br&&pool[bl]<=pool[i]) bl++; Pl[i]=al-1, pr[i]=bl-1; if(pl[i]<st[x<<1]) pl[i]=0; if(Pr[i]<st[(x<<1)|1]) pr[i]=0; }}inlinevoidRANKPT (intXintp) {V[x]= (p?p-st[x]+1:0); TAG[X]=p;} InlinevoidPushdown (intx) {    if(tag[x]<0)return; intp=Tag[x]; RANKPT (x<<1, Pl[p]); Rankpt ((x<<1)|1, Pr[p]); TAG[X]=-1;}voidUpdateintXintAintBintp) {    if(L<=a && b<=r) {rankpt (x,p);return;}    Pushdown (x); intMid= (a+b) >>1; if(l<=mid) Update (x<<1, A,mid,pl[p]); if(r>mid) Update ((x<<1)|1, mid+1, B,pr[p]); V[X]=v[x<<1]+v[(x<<1)|1];}voidQueryintXintAintb) {    if(L<=a && b<=R) {ans+=V[x]; return;    } pushdown (x); intMid= (a+b) >>1); if(l<=mid) query (x<<1, A,mid); if(r>mid) query ((x<<1)|1, mid+1, B); V[X]=v[x<<1]+v[(x<<1)|1];} InlineintLowerintx) {    //Lower_bound (pool+st[1],pool+ed[1]+1,x);    intl=st[1],r=en[1],mid,t=0;  while(l<=R)if(Pool[mid= (L+r) >>1]<=x) l= (t=mid) +1; Elser=mid-1; returnt;}intSeeda, seedb, C = ~ (1<< to), MM = (1<< -)-1;intRndintLast ) {Seeda= (36969+ (Last >>3)) * (Seeda & MM) + (Seeda >> -); SeeDB= (18000+ (Last >>3)) * (SeeDB & MM) + (SeeDB >> -); return(C & (Seeda << -) (+ seedb))%1000000000;}intMain () {intT,ku; scanf ("%d",&t);  while(t--) {scanf ("%d%d%d%d",&n,&m,&seeda,&seedb);  for(i=1; i<=n;i++) scanf ("%d", A +i);  for(i=1; i<=n;i++) scanf ("%d", B +i); Ans=sum=cur=0; Build (1,1, N);  for(i=1; i<=m;i++) {L=rnd (ANS)%n+1, R=rnd (ANS)%n+1, Ku=rnd (ans) +1; intkkk=Lower (KU); if(L>r) l^=r^=l^=R; if((L+r+ku) &1) Update (1,1, N,lower (KU)); Else{ans=0; Query (1,1, N); Sum= (sum+ (ll) I*ans)%1000000007; }} printf ("%i64d\n", sum); }    return 0;}
View Code

hdu5737 (2016 Multi-school League 2nd game D)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.