您的位置:首页 > 其它

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

2017-12-27 20:56 253 查看
二次联通门 : 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
= l, R
= 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.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
== R
)
{
if (t == 1) key
.a = 1;
else if (t == 2) key
.b = 1;
else if (t == 3) key
.c = 1;
else if (t == 4) key
.d = 1;

if (t == -1) key
.a = 0;
else if (t == -2) key
.b = 0;
else if (t == -3) key
.c = 0;
else if (t == -4) key
.d = 0;

Upsig (n);
return ;
}
int m = L
+ R
>> 1;
if (p <= m) Modi (n << 1, p, t), if (p > m) Modi (n << 1 | 1, p, t);
key
= key[n << 1] + key[n << 1 | 1];
}

D Query (int n, int l, int r)
{
if (l <= L
&& R
<= r) return key
;
int m = L
+ R
>> 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: