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. CentOS 安装jira 6.3.6

    java 目录: /usr/java/jdk1.6.0_45 tomcat 目录:/usr/tomcat-7.0.29 jira 目录: /usr/local/jira jira 访问地址: cent ...

  2. keras写模型时遇到的典型问题,也是最基础的类与对象问题

    自己定义了一个卷积类,现在需要把卷积加入model中,我的操作是这样的: model.add(Convolution1dLayer) 这样就会报错: 正确的写法是: model.add(Convolu ...

  3. IntelliJ IDEA隐藏不想看到的文件或文件夹

    打开IntelliJ IDEA,File -> Settings -> Editor -> File Types 在红框部分加上你想过滤的文件或文件夹名

  4. H5上传图片,并且显示进度条

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. vlc源码分析(三) 调用live555接收RTSP数据

    首先了解RTSP/RTP/RTCP相关概念,尤其是了解RTP协议:RTP与RTCP协议介绍(转载). vlc使用模块加载机制调用live555,调用live555的文件是live555.cpp. 一. ...

  6. c#中的结构

    1.在c#中,结构是值类型的数据结构,它可以使用一个单一的变量存储各种数据类型的相关数据,使用Struct关键字进行声明. 2.C#中结构的特点: (1)结构中可以有字段,属性,方法,运算表达式,事件 ...

  7. VC中TRACE ASSERT VERIFY之用法

    一.TRACE宏     当选择了Debug目标,并且afxTraceEnabled变量被置为TRUE时,TRACE宏也就随之被激活了.但在程序的Release版本中,它们是被完全禁止的.下面是一个典 ...

  8. nodejs运行的时候报错:Error: write EIO以及乱码解决方式

    在运行node.js的过程中报如下错误: events.js:72 throw er; // Unhandled 'error' event ^ Error: write EIO at errnoEx ...

  9. Extjs 中callParent的作用

    callParent 是 Sencha 类系统提供的一个用于调用你父/祖先类中的方法. 这个通常用于当你 继承一个框架类 或者 覆写一个类中提供的方法(比如 onRender) 时. 当你在一个带参数 ...

  10. Mongodb安装步骤(基于mongodb-3.2.12-tar.gz)

    1. 下载mongodb数据库:https://www.mongodb.com/download-center#community 2. 加压tar.gz压缩包,把解压文件拷贝到程序目录即可 3. 创 ...