1018: [SHOI2008]堵塞的交通traffic

链接

分析:

  用线段树维护区间的四个端点的联通情况,然后查询的时候,把所有覆盖到的区间合并起来即可。

  六种情况左上到右上(左边到右边的情况)……,左上到左下(同一侧相互到达的情况)……

  同一侧相互到达的情况,查询[l,r]是查的不完全。因为还有可能是先往左边走几步,下去,在走回来。这时候,查询一下[1,l]的情况,或起来即可。

代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} #define Root 1, n, 1
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1 const int N = ; struct Node{
bool l, r, s, x, a, b, t[];
Node () {l = r = s = x = a = b = t[] = t[] = ; }
}T[N << ];
int n, A1, A2, B1, B2; Node operator + (const Node &p, const Node &q) {
Node ans;
ans.t[] = q.t[], ans.t[] = q.t[];
if (p.l || (p.s && p.t[] && q.l && p.t[] && p.x)) ans.l = ;
if (q.r || (q.s && p.t[] && p.r && p.t[] && q.x)) ans.r = ;
if ((p.s && p.t[] && q.s) || (p.b && p.t[] && q.a)) ans.s = ;
if ((p.x && p.t[] && q.x) || (p.a && p.t[] && q.b)) ans.x = ;
if ((p.x && p.t[] && q.a) || (p.a && p.t[] && q.s)) ans.a = ;
if ((p.s && p.t[] && q.b) || (p.b && p.t[] && q.x)) ans.b = ;
return ans;
}
void build(int l,int r,int rt) {
if (l == r) {
T[rt].s = T[rt].x = ; return ;
}
int mid = (l + r) >> ;
build(lson); build(rson);
T[rt] = T[rt << ] + T[rt << | ];
}
void update1(int l,int r,int rt,int p,int opt) {
if (l == r) {
T[rt].t[A1 - ] = opt; return;
}
int mid = (l + r) >> ;
if (p <= mid) update1(lson, p, opt);
else update1(rson, p, opt);
T[rt] = T[rt << ] + T[rt << | ];
}
void update2(int l,int r,int rt,int p,int opt) {
if (l == r) {
T[rt].l = T[rt].r = T[rt].a = T[rt].b = opt;
return ;
}
int mid = (l + r) >> ;
if (p <= mid) update2(lson, p, opt);
else update2(rson, p, opt);
T[rt] = T[rt << ] + T[rt << | ];
}
Node query(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) {
return T[rt];
}
int mid = (l + r) >> ;
if (L > mid) return query(rson, L, R); // 注意这里的返回值,不能直接用一个ans来加
else if (R <= mid) return query(lson, L, R);
else return query(lson, L, R) + query(rson, L, R);
}
bool solve() {
int L = query(Root, , B1).r;
int R = query(Root, B2, n).l;
Node now = query(Root, B1, B2);
if (A1 == A2) {
if ((A1 == ) && (now.s || (L && now.a) || (now.b && R) || (L && now.x && R))) return ; // A1的判断!!!
if ((A1 == ) && (now.x || (L && now.b) || (now.a && R) || (L && now.s && R))) return ;
} else {
if ((A1 == ) && (now.b || (now.s && R) || (L && now.x) || (L && now.a && R))) return ;
if ((A1 == ) && (now.a || (now.x && R) || (L && now.s) || (L && now.b && R))) return ;
}
return ;
}
int main() {
n = read(); char opt[];
build(Root);
while (true) {
scanf("%s", opt);
if (opt[] == 'E') break;
A1 = read(), B1 = read(), A2 = read(), B2 = read();
if (B1 > B2) swap(A1, A2), swap(B1, B2);
if (opt[] == 'A') puts(solve() ? "Y" : "N");
else {
if (B1 != B2) update1(Root, B1, opt[] == 'O' ? : );
else update2(Root, B1, opt[] == 'O' ? : );
}
}
return ;
}

1018: [SHOI2008]堵塞的交通traffic的更多相关文章

  1. 数据结构(线段树):BZOJ 1018: [SHOI2008]堵塞的交通traffic

    1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 2638  Solved: 864 Descri ...

  2. BZOJ 1018 [SHOI2008]堵塞的交通traffic

    1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 2247  Solved: 706[Submit ...

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

    1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 3064  Solved: 1027[Submi ...

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

    Description 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一 ...

  5. 【BZOJ】1018: [SHOI2008]堵塞的交通traffic

    http://www.lydsy.com/JudgeOnline/problem.php?id=1018 题意:有2行,每行有c(c<=100000)个城市,则一共有c-1个格子,现在有q(q& ...

  6. [BZOJ 1018] [SHOI2008] 堵塞的交通traffic 【线段树维护联通性】

    题目链接:BZOJ - 1018 题目分析 这道题就说明了刷题少,比赛就容易跪..SDOI Round1 Day2 T3 就是与这道题类似的..然而我并没有做过这道题.. 这道题是线段树维护联通性的经 ...

  7. BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1018 用线段树维护区间连通性,对于每一个区间记录6个域表示(左上,左下)(左上,右上)(右上, ...

  8. BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树分治+并查集)

    传送门 解题思路 可以离线,然后确定每个边的出现时间,算这个排序即可.然后就可以线段树分治了,连通性用并查集维护,因为要撤销,所以要按秩合并,时间复杂度\(O(nlog^2 n)\) 代码 #incl ...

  9. bzoj千题计划108:bzoj1018: [SHOI2008]堵塞的交通traffic

    http://www.lydsy.com/JudgeOnline/problem.php?id=1018 关键点在于只有两行 所以一个2*m矩形连通情况只有6种 编号即对应代码中的a数组 线段树维护 ...

随机推荐

  1. BeanDefinition的创建(BeanDefinitionHolder的创建)

    这个对另一篇章Bean Definition从加载.解析.处理.注册到BeanFactory的过程的扩展. Spring框架中BeanDefinition的继承结构. Spring框架中BeanDef ...

  2. Python的getattr(),setattr(),delattr(),hasattr()及类内建__getattr__应用

    @Python的getattr(),setattr(),delattr(),hasattr() 先转一篇博文,参考.最后再给出一个例子 getattr()函数是Python自省的核心函数,具体使用大体 ...

  3. fpn

    class-aware detector 和 class-agnostic detector:https://blog.csdn.net/yeyang911/article/details/68484 ...

  4. Fedora Server 上配置 MariaDb 集群

    下载与安装 MariaDB Galera Cluster 10.1之前的版本安装,输入以下命令进行安装: sudo dnf install mariadb-galera-server 如果电脑上还没安 ...

  5. parse.JSON()报错是什么原因?

    哪里出错了? JSON.parse() 会把一个字符串解析成 JSON 对象.如果字符串书写正确,那么其将会被解析成一个有效的 JSON,但是这个字符串被检测出错误语法的时候将会抛出错误. 示例 JS ...

  6. 【Git】将项目下的.git目录隐藏

    将项目下的.git目录隐藏 在apache配置文件httpd.conf中添加配置: <Directory "${INSTALL_DIR}/www/mypro/.git"> ...

  7. Linux 防止rm -rf 误删Shell脚本

    #!/bin/bash #:set ff=unix #:set nobomb #-*- coding:utf-8 -*- ####################################### ...

  8. 有关dubbo面试的那些事儿

    dubbo是什么 dubbo是一个分布式框架,远程服务调用的分布式框架,其核心部分包含: 集群容错:提供基于接口方法的透明远程过程调用,包括多协议支持,以及软负载均衡,失败容错,地址路由,动态配置等集 ...

  9. sizeof 用于返回一个对象或者类型所占据的内存数

    整数类型 sizeof(int); 4字节or8字节 函数 sizeof(函数); 函数返回值类型占据的字节数 字符数组 char c[] = "abc"; sizeof(c); ...

  10. 基于Centos7系统部署cobbler批量安装系统

    前言 cobbler是一个可以实现批量安装系统的Linux应用程序.它有别于pxe+kickstart,cobbler可以实现同个服务器批量安装不同操作系统版本 系统环境的准备及下载cobbler 一 ...