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

Posted ZlycerQan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BZOJ 1018: [SHOI2008]堵塞的交通traffic相关的知识,希望对你有一定的参考价值。

二次联通门 : 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的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ1018[SHOI2008]堵塞的交通traffic 线段树

BZOJ 1018: [SHOI2008]堵塞的交通traffic [线段树 区间信息]

BZOJ1018: [SHOI2008]堵塞的交通traffic

[BZOJ]1018 堵塞的交通(SHOI2008)

Bzoj1018 [SHOI2008]堵塞的交通traffic

bzoj1018 [SHOI2008]堵塞的交通traffic——线段树