hdu5618 Jam ' s problem again

Source: Internet
Author: User

Want to use the dynamic open point of the two-dimensional line tree water, but the tle ... Some of the line tree set balance tree is over ... It is possible that the segment tree segment tree and the dynamic open point constant is really big ...

After finishing the third chapter of the brush, and then the tree set of trees, and CDQ division, and so on, and so on CDQ Division I will come back with a positive solution to this problem, the code has not been the first to stay.

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#defineREP (I,A,B) for (int i=a;i<=b;i++)#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;//const int maxn=1000100;Const intinf=1e9+Ten;Const intn=100010;intN;structpoint{intx, Y, Z intID; intans; FriendBOOL operator<(Point A,point B) {returna.z<b.z; }}; Point P[n];structnode{intL,r; intLz,rz; intCNT; intLx,rx; intLy,ry;}; Node Tr[n*8];inttrn;ints[n*8],trn2;intRT;BOOLCMP (Point a,point B) {returna.id<b.id;}intNewNodeintLintRintLzintRZ) {    intK; if(TRN2) k=s[trn2--]; Elsei=i+trn; TR[K]={l,r,lz,rz,0,-1,-1,-1,-1}; returnK;}voidInit (intLintRintLzintRZ) {TRN=trn2=0; RT=NewNode (L,R,LZ,RZ);}voidFree (int&k) {    if(k==-1)return;    Free (TR[K].LX);    Free (TR[K].RX);    Free (tr[k].ly);    Free (tr[k].ry); s[++trn2]=K; K=-1;}voidUpy (intRT) {tr[rt].cnt=0; if(~tr[rt].ly) {tr[rt].cnt+=tr[tr[rt].ly].cnt; if(tr[tr[rt].ly].cnt==0) free (tr[rt].ly); }    if(~Tr[rt].ry) {tr[rt].cnt+=tr[tr[rt].ry].cnt; if(tr[tr[rt].ry].cnt==0) free (tr[rt].ry); }}voidUpdatey (intPintCintRT) {    intL=tr[rt].l,r=TR[RT].R; intlz=tr[rt].lz,rz=Tr[rt].rz; if(lz==RZ) {tr[rt].cnt++; return; }    intM= (LZ+RZ) >>1; if(p<=m) {        if(tr[rt].ly==-1) tr[rt].ly=NewNode (l,r,lz,m);    Updatey (p,c,tr[rt].ly); }    Else{        if(tr[rt].ry==-1) Tr[rt].ry=newnode (l,r,m+1, RZ);    Updatey (P,c,tr[rt].ry); } upy (RT);}intQueryy (intLintRint&RT) {    if(tr[rt].cnt==0&&rt!=1) {free (RT); return 0; }    intL=tr[rt].l,r=TR[RT].R; intlz=tr[rt].lz,rz=Tr[rt].rz; if(L&LT;=LZ&AMP;&AMP;RZ&LT;=R)returntr[rt].cnt; intM= (LZ+RZ) >>1; intres=0; if(l<=m) {        if(~tr[rt].ly) res+=Queryy (l,r,tr[rt].ly); }    if(r>m) {        if(~tr[rt].ry) res+=Queryy (L,r,tr[rt].ry); }    returnRes;}voidUpdatex (intXintYintCintRT) {    //cout<< "x=" <<x<< "y=" <<y<< "c=" <<c<< "rt=" <<rt<<endl;    intL=tr[rt].l,r=TR[RT].R; intlz=tr[rt].lz,rz=Tr[rt].rz; //cout<< "x=" <<x<< "y=" <<y<< "c=" <<c<< "l=" <<l<< "r=" < <r<< "lz=" <<lz<< "rz=" <<rz<<endl;Updatey (Y,C,RT); if(L==R)return; intM= (l+r) >>1; if(x<=L) {        if(tr[rt].lx==-1) tr[rt].lx=NewNode (L,M,LZ,RZ);    Updatex (X,Y,C,TR[RT].LX); }    Else{        if(tr[rt].rx==-1) Tr[rt].rx=newnode (m+1, R,lz,rz);    Updatex (X,Y,C,TR[RT].RX); }}intQueryx (intXlintXR,intYlintYR,int&RT) {    if(tr[rt].cnt==0&&rt!=1) {free (RT); return 0; }    intL=tr[rt].l,r=TR[RT].R; intlz=tr[rt].lz,rz=Tr[rt].rz; //cout<< "xl=" <<xL<< "xr=" <<xR<< "yl=" <<yL<< "yr=" <<yR<< "l = "<<l<<" r= "<<r<<" lz= "<<lz<<" rz= "<<rz<<endl;    if(XL&LT;=L&AMP;&AMP;R&LT;=XR)returnQueryy (YL,YR,RT); intM= (l+r) >>1; intres=0; if(xl<=L) {        if(~TR[RT].LX)returnres+=Queryx (XL,XR,YL,YR,TR[RT].LX); }    if(xr>m) {        if(~TR[RT].RX)returnres+=Queryx (XL,XR,YL,YR,TR[RT].RX); }    returnRes;}intMain () {Freopen ("In.txt","R", stdin); intT;cin>>T;  while(t--) {scanf ("%d",&N); REP (i,1, N) scanf ("%d%d%d", &p[i].x,&p[i].y,&p[i].z), p[i].id=i; Sort (P+1, p+n+1); Init (1N1, N); REP (i,1, N) {            //cout<<p[i].x<< "" <<p[i].y<< "" <<p[i].z<<endl;P[i].ans=queryx (1, p[i].x,1, P[I].Y,RT); Updatex (P[I].X,P[I].Y,1, RT); //cout<<p[i].ans<<endl;        }         for(inti=n-1; i>=1; i--)if(p[i].x==p[i+1].x&&p[i].y==p[i+1].y&&p[i].z==p[i+1].Z) p[i].ans=p[i+1].ans; Sort (P+1, p+n+1, CMP); REP (i,1, N) printf ("%d\n", P[i].ans); }    return 0;}
View Code

hdu5618 Jam ' s problem again

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.