"Bzoj" 1018: [SHOI2008] clogged traffic traffic

Source: Internet
Author: User

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

Test instructions: There are 2 lines, each line has a C (c<=100000) city, then there are c-1 lattice, there is now a Q (q<=100000) operation, operation Open and Close is the four corners of the grid adjacent to the city edge or cut edge, operation ask is to ask two cities are connected

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x) puts ("error"): 0) #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) inline const int Getint () {int r=0, k=1; Char c=g Etchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }const int n=100005;struct T {bool d[2][2], f[2]; T () {CC (d, 0); CC (f, 0); }}t[n<<2];int N, a[n][4], tot; #define LC x<<1#define RC X<<1|1#define Lson L, Mid, Lc#define Rson mid+1 , R, Rcvoid upd1 (T &x, int pos=-1) {static bool ok[4][4]; CC (OK, 0), if (pos==-1) {if (x.d[0][0]) ok[0][2]=ok[2][0]=1;if (x.d[0][1]) ok[0][3]=ok[3][0]=1;if (x.d[1][0]) ok[1][2]= Ok[2][1]=1;if (X.d[1][1]) ok[1][3]=ok[3][1]=1;if (x.f[0]) ok[0][1]=ok[1][0]=1;if (x.f[1]) ok[2][3]=ok[3][2]=1;} else {CC (x.d, 0); CC (X.F, 0), if (A[pos][0]) ok[0][2]=ok[2][0]=1;if (a[pos][1]) ok[0][1]=ok[1][0]=1;if (a[pos][2]) ok[1][3]=ok[3][1]=1; if (a[pos][3]) ok[3][2]=ok[2][3]=1;} Rep (i, 4) ok[i][i]=1;rep (K, 4) Rep (I, 4) if (Ok[i][k]) Rep (J, 4) if (Ok[k][j]) ok[i][j]=1;if (ok[0][1]) x.f[0]=1;if (ok[0][2) ) x.d[0][0]=1;if (ok[0][3]) x.d[0][1]=1;if (ok[2][3]) x.f[1]=1;if (ok[1][2]) x.d[1][0]=1;if (ok[1][3]) x.d[1][1]=1;} void Pushup (t &x, T &l, T &r) {x.d[0][0]= (l.d[0][0]&&r.d[0][0]) | | (L.d[0][1]&&r.d[1][0]); x.d[0][1]= (l.d[0][0]&&r.d[0][1]) | | (l.d[0][1]&&r.d[1][1]); x.d[1][0]= (l.d[1][0]&&r.d[0][0]) | | (L.d[1][1]&&r.d[1][0]); x.d[1][1]= (l.d[1][0]&&r.d[0][1]) | | (L.d[1][1]&&r.d[1][1]); X.f[0]=l.f[0] | | (L.d[0][0]&&r.f[0]&&l.d[1][1]); X.f[1]=r.f[1] | | (R.d[0][0]&&l.f[1]&&r.d[1][1]);} void Update (int pos, int l=1, int r=tot, int x=1) {if (l==r) {UPD1 (t[x], POS); return;} int mid= (L+R) >>1;if (pos<=mid) Update (POS, Lson), Else Update (POS, Rson);p ushup (T[x], T[LC], T[RC]);} void Ask (int L, int R, T &ret, int l=1, int r=tot, int x=1) {if (l<=l && r<=r) {memcpy (ret.d, T[X].D, si Zeof (RET.D)); memcpy (RET.F, T[X].F, sizeof (RET.F)); Return }int mid= (l+r) >>1;if (r<=mid) {Ask (L, R, ret, Lson); return;} if (mid<l) {Ask (L, R, ret, Rson); return;} T T1, T2;ask (L, R, T1, Lson); Ask (L, R, T2, Rson);p ushup (ret, T1, T2);} void change (int x1, int y1, int x2, int y2, int f) {if (y1==y2) {if (y1==n) {a[y1-1][3]=f;update (y1-1);} else if (y1==1) {a[y1][1]=f;update (y1);} else {a[Y1-1][3]=f;a[y1][1]=f;update (y1-1); update (y1);}} else {if (x1==0) a[y1][0]=f;if (x1==1) a[y1][2]=f;update (y1);} T tt;//Ask (1, 1, TT); DBG (Tt.d[0][0]); DBG (tt.d[0][1]); DBG (Tt.d[1][0]); DBG (tt.d[1][1]); DBG (Tt.f[0]); DBG (tt.f[1]);//DBG (a[1][0]); DBG (A[1][3]);} void Ask (int x1, int y1, int x2, int y2) {if (x1==x2 && y1==y2) {puts ("Y"); return;} T L, R, Mid;if (y1==y2) {if (y1==n) {Ask (1, tot, mid), if (Mid.f[1]) puts ("Y"), Else puts ("n");} else if (y1==1) {Ask (1, tot, mid), if (Mid.f[0]) puts ("Y"), Else puts ("N");} else {Ask (1, y1-1, L), ask (Y1, tot, R), if (L.f[1] | | r.f[0]) puts ("Y"); else puts ("N");}} else {if (y1-1>=1) Ask (1, y1-1, L), if (Y2<=tot) Ask (Y2, tot, R), ask (Y1, y2-1, mid), if (mid.d[x1][x2]) {puts ("Y"); Retu Rn }if (y1-1>=1 && l.f[1]) mid.f[0]=1;if (Y2<=tot && r.f[0]) MID.F[1]=1;UPD1 (mid); if (mid.d[x1][x2]) Puts ("Y"); else puts ("N");}} Char S[10];int main () {read (n); Tot=n-1;while (scanf ("%s", s), s[0]!= ' E ') {int x1=getint (), Y1=getint (), X2=getint (), y2=g Etint (); --x1;  --x2;if (y1>y2) swap (x1, x2), swap (Y1, y2), if (s[0]== ' O ') change (x1, y1, x2, y2, 1), and else if (s[0]== ' C ') change (x1, y1, x2, y2, 0); else ask (x1, y1, x2, y2);} return 0;}

  

There's a lot of room to spit on this question!!!!!!!!!!!!!!!!!!!!!!!!!!

First of all, it's a pit, and now it's filled up .... Long ago to write their own casually yy a similar lct-like pointers (with and check the set to engage in the LCT ... Although there is no path compression) to turn up wa ... Because I'm layering the whole picture and then messing around ....

Then I looked at the puzzle and found it was a very divine line-tree .... Then knocked himself yy but came to give up ....

And then some time later I want to fill out this hole ... But in accordance with their own yy do not find the wrong and then give up ...

Then last night I came to do qaq found actually very good to think ... is to maintain the connectivity well blabla. So happily 1h bar not to knock well and over the sample and static check the wrong .... Even WA Qaq and then create data and violence against Pat .... Small data all over ..... So look for the standard to shoot .... Finally made a set of data .... But..... This is the data of the n=2000 can be adjusted? Then return to the static error-checking state to ... But why does it seem so tired? I've been staring at the screen and the paper. Output debugging clap and Pat ... Sure enough, it's too weak ... Filming until the early hours of the morning has not been done .... 4h has been wasted (this great story tells us that when the situation is not good, do not think about the problem Qaq not to debug ...

It was too weak .... So today at noon to pits (because to root to the data ... First evaluation of the next ... 80 points ..... Then static check a bit. Immediately found SB wrong ... (Sure enough to calm down + have the energy to the naked eye to do the problem Ah Qaq) and then a "...

It is still too weak ....

The puzzle: Because there are only two lines, so the state can be designed for each lattice, so only c-1 lattice (behind the c-1 as N), first to analyze the case of only one lattice. Obviously to maintain connectivity between the 4 cities I Floyd directly ... Consider the case of multiple grids connected together ... If we ask for the connectivity of [L, R] City (i.e. [L, r-1] lattice, assuming that the lattice numbering starts from 1 to the left to the right), then you can use something to maintain the entire interval of the lattice, the answer is the entire interval boundary of the 4 points of connectivity .... Found that is not all very similar, that is, multiple grids and a lattice are to take the boundary of the 4 points to judge .... And [L, R-1] can be combined by ... So on the line segment tree ... Orz (anyway I didn't yy out line tree) that is, for [L, R] Lattice (this interval is not the upper one), we assume that there is a middle point mid, you can be known [L, mid], [Mid+1, R] connectivity and the introduction of [L, R] connectivity. (Push your own hand ...) Such problems are solved ...

But it is not enough to answer the question simply by looking for the connectivity of [L, R] above. Because there may be [L, R] the left and right boundary in [L, R] This interval is no edge or not connected ... But it may be possible to find a path in the <=l to make the left edge of L connected, so we'll look at [1, L-1], and see if the right edge of L-1 is connected to know the left edge of this lattice ... r ...

The last hint, that is my SB wrong, must pay attention to the serial number .... Is the relationship between the city and the lattice ordinal ... The lattice corresponding to the X-column may have x-1 and x in this lattice.

"Bzoj" 1018: [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.