1018: [SHOI2008]堵塞的交通traffic
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的更多相关文章
- 数据结构(线段树):BZOJ 1018: [SHOI2008]堵塞的交通traffic
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 2638 Solved: 864 Descri ...
- BZOJ 1018 [SHOI2008]堵塞的交通traffic
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 2247 Solved: 706[Submit ...
- BZOJ 1018: [SHOI2008]堵塞的交通traffic [线段树 区间信息]
1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 3064 Solved: 1027[Submi ...
- 1018: [SHOI2008]堵塞的交通traffic - BZOJ
Description 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一 ...
- 【BZOJ】1018: [SHOI2008]堵塞的交通traffic
http://www.lydsy.com/JudgeOnline/problem.php?id=1018 题意:有2行,每行有c(c<=100000)个城市,则一共有c-1个格子,现在有q(q& ...
- [BZOJ 1018] [SHOI2008] 堵塞的交通traffic 【线段树维护联通性】
题目链接:BZOJ - 1018 题目分析 这道题就说明了刷题少,比赛就容易跪..SDOI Round1 Day2 T3 就是与这道题类似的..然而我并没有做过这道题.. 这道题是线段树维护联通性的经 ...
- BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1018 用线段树维护区间连通性,对于每一个区间记录6个域表示(左上,左下)(左上,右上)(右上, ...
- BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树分治+并查集)
传送门 解题思路 可以离线,然后确定每个边的出现时间,算这个排序即可.然后就可以线段树分治了,连通性用并查集维护,因为要撤销,所以要按秩合并,时间复杂度\(O(nlog^2 n)\) 代码 #incl ...
- bzoj千题计划108:bzoj1018: [SHOI2008]堵塞的交通traffic
http://www.lydsy.com/JudgeOnline/problem.php?id=1018 关键点在于只有两行 所以一个2*m矩形连通情况只有6种 编号即对应代码中的a数组 线段树维护 ...
随机推荐
- BZOJ3781:小B的询问(莫队)
Description 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L ...
- BZOJ2761:[JLOI2011]不重复数字(map)
Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...
- Django中模型(五)
Django中模型(五) 六.模型查询 1.概述 查询集,表示从数据库获取的对象集合. 过滤器就是一个函数,基于所给的参数限制查询集结果.查询集可以有多个过滤器. 从sql角度来说,查询集合等价于se ...
- docker-8-本地镜像发布到阿里云
镜像的生成方法 1.前面的DockerFile 2.从容器创建一个新的镜像 docker commit [OPTIONS] 容器ID [REPOSITORY[:TAG]] 将本地镜像推送到阿里云 ...
- Elasticsearch + Elasticsearch-head搭建
Elasticsearch搭建: [root@hdoop3 elk]# tar -xvf elasticsearch-6.2.4.tar [root@hdoop3 elk]# cd elasticse ...
- 所有流媒体协议,编解码规范和媒体封装格式的datasheet的下载地址
https://github.com/jiayayao/DataSheet All datasheet about stream protocol, encode-decode spec and me ...
- 使用Docker遇到的基本命令及问题小结
当遇到Cannot connect to the Docker daemon. Is the docker daemon running on this host?导致Docker无法启动时,重启Do ...
- C#实体更新指定的字段
接口类: /// <summary> /// 更新指定字段 /// </summary> /// <param name="entity">实体 ...
- Java Activiti 工作流引擎 springmvc SSM 流程审批 后台框架源码
1.模型管理 :web在线流程设计器.预览流程xml.导出xml.部署流程 2.流程管理 :导入导出流程资源文件.查看流程图.根据流程实例反射出流程模型.激活挂起 3.运行中流程:查看流程信息.当前任 ...
- 决策树 - 可能是CART公式最严谨的介绍
目录 决策树算法 ID3算法[1] C4.5 改进[1] "纯度"度量指标:信息增益率 离散化处理 CART(分类与回归树,二叉) 度量指标 二值化处理 不完整数据处理 CART生 ...