BZOJ1018: [SHOI2008] clogged traffic traffic

Source: Internet
Author: User

Segment tree maintains connectivity.

Below the topic there is analysis.

The number of lines in the puzzle is equal to the number of rows in the title-1.

analysed altogether (R1,C1)--(R2,C2) a total of four ways.

Suppose R1=1,r2=0.

1. Go directly to the past.

2. First come (0,C1) and then go over.

3. First come (1,C2) and then go over.

4. Go first (0,C1) and then (1,C2) to the past.

With an array of a1[i][j], maintain the line of I from the leftmost X-node to the far right of J-line.

Another array, a2[i],a2[0], indicates that the point at the far right of the X node can be wrapped from one side to another. A2[1] represents the leftmost point on the left to be able to move from the left to another line.

#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN =800000+Ten;Chars[ -];intx1,x2,y1,y2,c;structSegtree {#defineLC (x) ((x) <<1)#defineRC (x) (((x) <<1) |#defineRoot 1structStatus {inta1[2][2],a2[2];        }S[MAXN]; BOOLb[maxn][2]; intL[MAXN],R[MAXN],M[MAXN]; Status update (Status S1,status S2,BOOLb[])        {Status res;  for(intI=0; i<=1; i++)          for(intj=0; j<=1; j + +) Res.a1[i][j]=s1.a1[i][0] && b[0] && s2.a1[0][J] | | s1.a1[i][1] && b[1] && s2.a1[1][j]; res.a2[0]=s1.a2[0] || s1.a1[0][0] && b[0] && s2.a2[0] && b[1] && s1.a1[1][1]; res.a2[1]=s2.a2[1] || s2.a1[0][0] && b[0] && s1.a2[1] && b[1] && s2.a1[1][1]; returnRes; } Status Access (intXintY1,inty2) {        if(Y1<=l[x] && r[x]<=y2)returnS[x]; Else if(Y2<=m[x])returnAccess (LC (x), y1,y2); Else if(Y1>m[x])returnAccess (RC (x), y1,y2); Else returnUpdate (Access (LC (x), y1,y2), Access (RC (x), y1,y2), b[x]); }        voidChangeBOOLKintXintX1,intY1,intX2,inty2) {        if(X1==x2 && y1==M[x]) {B[X][X1]=K; S[X]=Update (S[LC (x)],S[RC (x)],b[x]); }        Else if(l[x]==r[x]) s[x].a1[0][1]=s[x].a1[1][0]=s[x].a2[0]=s[x].a2[1]=K; Else{Change (k,y2&LT;=M[X]?LC (X): RC (x), x1,y1,x2,y2); S[X]=Update (S[LC (x)],S[RC (x)],b[x]); }    }        voidAskintX1,intY1,intX2,inty2) {Status Left=access (Root,1, y1), right=Access (root,y2,c), Mid=access (ROOT,Y1,Y2); BOOLres=false;  for(intI=0; i<=1; i++)         for(intj=0; j<=1; j + +)            if(mid.a1[i][j]&& (i==x1| | left.a2[1]) && (j==x2| | right.a2[0]) {res=true; Break; } printf (res?"y\n":"n\n"); }        voidBuildintXintY1,inty2) {L[x]=y1,r[x]=y2,m[x]= (L[x]+r[x]) >>1; if(y1==y2) s[x].a1[0][0]=s[x].a1[1][1]=true; Else{Build (LC (x), y1,m[x]); Build (RC (x), m[x]+1, y2); }}}seg;intMain () {scanf ("%d",&c); Seg.build (1,1, c);  while(1) {scanf ("%s", s); if(s[0]=='E') Break; scanf ("%d%d%d%d",&x1,&y1,&x2,&y2); --x1; --x2; if(y1>y2)            {swap (X1,X2);            Swap (Y1,Y2); }        if(s[0]=='O') Seg.change (1,1, X1,y1,x2,y2); Else if(s[0]=='C') Seg.change (0,1, X1,y1,x2,y2); ElseSeg.ask (X1,Y1,X2,Y2); }        return 0; }

BZOJ1018: [SHOI2008] clogged traffic traffic

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.