Bzoj 1018: [SHOI2008] Blocked traffic traffic (segment tree)

Source: Internet
Author: User

Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1018

Maintain interval connectivity with segment tree, for each interval record 6 fields (upper left, bottom left) (upper left, upper right) (upper right, bottom right) (upper left, bottom left) (lower-right, lower-left) (top-bottom, right-bottom) connectivity.

Because it is a relationship with neighboring points, maintaining an array represents the current column x and column x+1 and the edge condition of the first row and the second row of the current column x.

Then there is the interval merge. Various classification discussions:

#include <cstring>#include<iostream>#include<algorithm>#include<cstdio>#include<queue>#include<map>#include<vector>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#definell Long Long#defineMAXN 100500#defineMM 998244353using namespacestd;structdata{intb[6],l,r;} T[MAXN*4];introad[maxn][3],n;Chars[Ten];intRead () {intx=0, f=1;CharCh=GetChar ();  while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();}  while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}    Data M (data L,data R) {data i; I.L=L.L; I.r=R.R; i.b[0]= (l.b[0])|| (((l.b[1]&&l.b[3]) || (l.b[4]&&l.b[5])) && (road[l.r][0]) && (road[l.r][1]) && (r.b[0])); i.b[2]= (r.b[2])|| (((r.b[1]&&r.b[3]) || (r.b[4]&&r.b[5])) && (road[l.r][0]) && (road[l.r][1]) && (l.b[2])); i.b[1]= (l.b[1]&&r.b[1]&&road[l.r][0]) || (l.b[4]&&r.b[5]&&road[l.r][1]); i.b[3]= (l.b[3]&&r.b[3]&&road[l.r][1]) || (l.b[5]&&r.b[4]&&road[l.r][0]); i.b[4]= (l.b[1]&&r.b[4]&&road[l.r][0]) || (l.b[4]&&r.b[3]&&road[l.r][1]); i.b[5]= (l.b[5]&&r.b[1]&&road[l.r][0]) || (l.b[3]&&r.b[5]&&road[l.r][1]); returni;}voidBuildintIintLintR) {T[I].L=l; T[i].r=r;intMid= (L+R)/2; if(L==R) {t[i].b[1]=t[i].b[3]=1;return; } Build (I*2, L,mid); Build (i*2+1, mid+1, R); T[i]=m (t[i*2],t[i*2+1]);}voidChangeintPosinti) {    intL=t[i].l,r=t[i].r,mid= (L+R)/2; if(l==R) {Rep (J,0,5) t[i].b[j]=road[l][2]; t[i].b[1]=t[i].b[3]=1; return; }    if(pos<=mid) Change (pos,i*2);ElseChange (pos,i*2+1); T[i]=m (t[i*2],t[i*2+1]);}voidChangeintX0,intY0,intX1,intY1,intflag) {    if(y0>y1) Swap (x0,x1), swap (Y0,Y1); if(x0==x1) {        if(x0==1) road[y0][0]=flag;Elseroad[y0][1]=Flag; } Elseroad[y0][2]=Flag; Change (y0,1);} Data Ask (intIintTlintTR) {    intL=t[i].l,r=t[i].r,mid= (L+R)/2; if(L==TL&AMP;&AMP;R==TR)returnT[i]; if(Tr<=mid)returnAsk (i*2, TL,TR); Else if(Tl>mid)returnAsk (i*2+1, TL,TR); Else returnM (Ask (i*2, Tl,mid), Ask (i*2+1, mid+1, TR));}BOOLQueryintX0,intY0,intX1,inty1) {    if(y0>y1) Swap (x0,x1), swap (Y0,Y1); Data x=ask (1,1, y0), Y=ask (1, y0,y1), Z=ask (1, Y1,n); if(x0==x1) {        if(x0==1){            if(y.b[1])return 1; if((x.b[2]|| y.b[0]) && (y.b[2]|| z.b[0]) &&y.b[3])return 1; if((y.b[4]) && (y.b[2]|| z.b[0]))return 1; if((y.b[5]) && (x.b[2]|| y.b[0]))return 1; return 0; }        Else {            if(y.b[3])return 1; if((x.b[2]|| y.b[0]) && (y.b[2]|| z.b[0]) &&y.b[1])return 1; if((y.b[5]) && (y.b[2]|| z.b[0]))return 1; if((y.b[4]) && (x.b[2]|| y.b[0]))return 1; return 0; }    }    Else {        if(x0==1){            if(y.b[4])return 1; if((x.b[2]|| y.b[0]) &&y.b[3])return 1; if((x.b[2]|| y.b[0]) && (y.b[2]|| z.b[0]) &&y.b[5])return 1; if((y.b[2]|| z.b[0]) &&y.b[1])return 1; return 0; }        Else {            if(y.b[5])return 1; if((x.b[2]|| y.b[0]) &&y.b[1])return 1; if((x.b[2]|| y.b[0]) && (y.b[2]|| z.b[0]) &&y.b[4])return 1; if((y.b[2]|| z.b[0]) &&y.b[3])return 1; return 0; }    }     }intMain () {n=read (); Build (1,1, N); intx0,x1,y0,y1;  while(1) {scanf ("%s", s); if(s[0]=='E') Break; X0=read (); Y0=read (); X1=read (); y1=read (); if(s[0]=='O') Change (X0,y0,x1,y1,1); Else if(s[0]=='C') Change (X0,y0,x1,y1,0); Elseprintf"%c\n", query (x0,y0,x1,y1)?'Y':'N'); }    return 0;}

Bzoj 1018: [SHOI2008] Blocked traffic traffic (segment tree)

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.