1. 程式人生 > >BZOJ 1018: [SHOI2008]堵塞的交通traffic

BZOJ 1018: [SHOI2008]堵塞的交通traffic

query pac wap esp define targe http cst 心情

二次聯通門 : BZOJ 1018: [SHOI2008]堵塞的交通traffic

/*

    BZOJ 1018: [SHOI2008]堵塞的交通traffic

    麻麻
    這題玩我

    這題簡直消磨人的意誌
    寫了一天了
    寫一段
    玩一段

    直接寫不下去
    什麽時候恢復一下心情再寫

*/
#include <cstdio>
#include <iostream>

#define rg register
inline void read (int &n)
{
    rg char c = getchar ();
    
for (n = 0; !isdigit (c); c = getchar ()); for (; isdigit (c); n = n * 10 + c - 0, c = getchar ()); } #define Max 200005 struct D { int a, b, c, d, e, f; D () { a = b = c = d = e = f = 0; } }; inline D operator + (const D &L, const D &R) { D n; n.d = L.d, n.b = R.b; n.a
= (L.a & R.a) | (L.e & R.f); n.c = (L.c & R.c) | (L.f & R.e); n.f = (L.c & R.f) | (L.f & R.a); n.e = (L.e & R.c) | (L.a & R.e); return n; } namespace seg { int L[Max << 2], R[Max << 2]; D key[Max << 2]; void Build (int n, int
l, int r) { L[n] = l, R[n] = r; if (l == r) return ; int m = l + r >> 1; Build (n << 1, l, m), Build (n << 1 | 1, m + 1, r); } inline void Upsig (int n) { D &n = key[n]; n.e = (n.a & n.b) | (n.c & n.d); n.f = (n.d & n.d) | (n.c & n.b); return ; } void Modi (int n, int p, int t) { if (L[n] == R[n]) { if (t == 1) key[n].a = 1; else if (t == 2) key[n].b = 1; else if (t == 3) key[n].c = 1; else if (t == 4) key[n].d = 1; if (t == -1) key[n].a = 0; else if (t == -2) key[n].b = 0; else if (t == -3) key[n].c = 0; else if (t == -4) key[n].d = 0; Upsig (n); return ; } int m = L[n] + R[n] >> 1; if (p <= m) Modi (n << 1, p, t), if (p > m) Modi (n << 1 | 1, p, t); key[n] = key[n << 1] + key[n << 1 | 1]; } D Query (int n, int l, int r) { if (l <= L[n] && R[n] <= r) return key[n]; int m = L[n] + R[n] >> 1; D res; if (l <= m) res = Query (n << 1, l, r); if (r > m) res = res + Query (n << 1 | 1, l, r); return res; } } int main (int argc, char *argv[]) { int N, M; read (N); rg int i, j; int x1, y1, x2, y2; D res; int t; for (char type[10]; ; ) { scanf ("%s", type); if (type[0] == E) break; if (type[0] == O) { read (x1), read (y1), read (x2), read (y2); if (x1 > x2) std :: swap (x1, x2), std :: swap (y1, y2); if (x1 == x2) { if (x1 != 1) seg :: Modi (1, x1 - 1, 2), seg :: Modi (1, x1, 4); else seg :: Modi (1, 1, 4); } else { if (y1 == 1) seg :: Modi (1, x1, 1); else seg :: Modi (1, x1, 3); } } #define Yes { puts ("Y"); continue; } #define No { puts ("N"); continue; } else if (type[0] == Q) // t == 1 { res = seg :: Query (1, x1, y1 - 1); if (x1 == x2 && y1 == y2) Yes if (x1 == x2) { if (res.a) Yes } if (y1 == y2) { } } else { } } return 0; }

BZOJ 1018: [SHOI2008]堵塞的交通traffic