题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1018

用线段树维护区间连通性,对于每一个区间记录6个域表示(左上,左下)(左上,右上)(右上,右下)(左下,右下)(左上,右下)(左下,右上)的连通情况。

因为是与相邻点的关系所以维护一个数组表示当前列x与列x+1的连边情况和当前列x的第一行与第二行的连边情况。

然后就是区间合并。。各种分类讨论。。

#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define ll long long
#define maxn 100500
#define mm 998244353
using namespace std;
struct data{int b[],l,r;
}t[maxn*];
int road[maxn][],n;
char s[];
int read(){
int x=,f=; char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-; ch=getchar();}
while (isdigit(ch)){x=x*+ch-''; ch=getchar();}
return x*f;
}
data M(data l,data r){
data i;
i.l=l.l; i.r=r.r;
i.b[]=(l.b[])||( ( (l.b[]&&l.b[]) || (l.b[]&&l.b[]) )&&(road[l.r][])&&(road[l.r][])&&(r.b[]));
i.b[]=(r.b[])||( ( (r.b[]&&r.b[]) || (r.b[]&&r.b[]) )&&(road[l.r][])&&(road[l.r][])&&(l.b[]));
i.b[]=(l.b[]&&r.b[]&&road[l.r][]) || (l.b[]&&r.b[]&&road[l.r][]);
i.b[]=(l.b[]&&r.b[]&&road[l.r][]) || (l.b[]&&r.b[]&&road[l.r][]);
i.b[]=(l.b[]&&r.b[]&&road[l.r][]) || (l.b[]&&r.b[]&&road[l.r][]);
i.b[]=(l.b[]&&r.b[]&&road[l.r][]) || (l.b[]&&r.b[]&&road[l.r][]);
return i;
}
void build(int i,int l,int r){
t[i].l=l; t[i].r=r; int mid=(l+r)/;
if (l==r){ t[i].b[]=t[i].b[]=; return; }
build(i*,l,mid); build(i*+,mid+,r);
t[i]=M(t[i*],t[i*+]);
}
void change(int pos,int i){
int l=t[i].l,r=t[i].r,mid=(l+r)/;
if (l==r){
rep(j,,) t[i].b[j]=road[l][];
t[i].b[]=t[i].b[]=;
return;
}
if (pos<=mid) change(pos,i*); else change(pos,i*+);
t[i]=M(t[i*],t[i*+]);
}
void change(int x0,int y0,int x1,int y1,int flag){
if (y0>y1) swap(x0,x1),swap(y0,y1);
if (x0==x1) {
if (x0==) road[y0][]=flag; else road[y0][]=flag;
} else road[y0][]=flag;
change(y0,);
}
data ask(int i,int tl,int tr){
int l=t[i].l,r=t[i].r,mid=(l+r)/;
if (l==tl&&r==tr) return t[i];
if (tr<=mid) return ask(i*,tl,tr);
else if (tl>mid) return ask(i*+,tl,tr);
else return M(ask(i*,tl,mid),ask(i*+,mid+,tr));
}
bool query(int x0,int y0,int x1,int y1){
if (y0>y1) swap(x0,x1),swap(y0,y1);
data x=ask(,,y0),y=ask(,y0,y1),z=ask(,y1,n);
if (x0==x1) {
if (x0==){
if (y.b[]) return ;
if ((x.b[]||y.b[])&&(y.b[]||z.b[])&&y.b[]) return ;
if ((y.b[])&&(y.b[]||z.b[])) return ;
if ((y.b[])&&(x.b[]||y.b[])) return ;
return ;
}
else {
if (y.b[]) return ;
if ((x.b[]||y.b[])&&(y.b[]||z.b[])&&y.b[]) return ;
if ((y.b[])&&(y.b[]||z.b[])) return ;
if ((y.b[])&&(x.b[]||y.b[])) return ;
return ;
}
}
else {
if (x0==){
if (y.b[]) return ;
if ((x.b[]||y.b[])&&y.b[]) return ;
if ((x.b[]||y.b[])&&(y.b[]||z.b[])&&y.b[]) return ;
if ((y.b[]||z.b[])&&y.b[]) return ;
return ;
}
else {
if (y.b[]) return ;
if ((x.b[]||y.b[])&&y.b[]) return ;
if ((x.b[]||y.b[])&&(y.b[]||z.b[])&&y.b[]) return ;
if ((y.b[]||z.b[])&&y.b[]) return ;
return ;
}
} }
int main(){
n=read();
build(,,n);
int x0,x1,y0,y1;
while (){
scanf("%s",s);
if (s[]=='E') break;
x0=read(); y0=read(); x1=read(); y1=read();
if (s[]=='O') change(x0,y0,x1,y1,);
else if (s[]=='C') change(x0,y0,x1,y1,);
else printf("%c\n",query(x0,y0,x1,y1)?'Y':'N');
}
return ;
}

BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树)的更多相关文章

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

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

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

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

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

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

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

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

  5. [BZOJ1018][SHOI2008]堵塞的交通traffic 线段树维护连通性

    1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec  Memory Limit: 162 MB Submit: 3795  Solved: 1253 [Sub ...

  6. 【BZOJ1018】[SHOI2008]堵塞的交通traffic 线段树

    [BZOJ1018][SHOI2008]堵塞的交通traffic Description 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个 ...

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

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

  8. 【bzoj1018】[SHOI2008]堵塞的交通traffic 线段树区间合并+STL-set

    题目描述 给出一张2*n的网格图,初始每条边都是不连通的.多次改变一条边的连通性或询问两个点是否连通. 输入 第一行只有一个整数C,表示网格的列数.接下来若干行,每行为一条交通信息,以单独的一行“Ex ...

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

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1018 巧妙的线段树.维护矩阵四个角的连通性. 考虑两个点连通的可能路径分成3部分:两点左边. ...

随机推荐

  1. ucore lab1练习2 qemu+gdb 不能协作调试的问题make lab1-mon

    本练习是qemu结合gdb调试,但是我做实验的时候并不能像视频输入make lab1-mon那样顺利调试,期间有各种error,后来我找到原因,请看解决方法. 请先把ucore_lab文件删除,以下全 ...

  2. 模板引擎(smarty)知识点总结五

    ---------重点知识:循环------------ /*   smarty 循环之for循环 */ /*    基本的语法         {for $i=$start to $end step ...

  3. type 命令详解

     type  作用: 用来显示指定命令的类型,判断出命令是内部命令还是外部命令. 命令类型: alias: 别名 keyword:关键字, shell 保留字 function:函数, shell函数 ...

  4. which 命令详解

    一.which 作用: which 命令用于查找并显示给定命令的绝对路径,环境变量PATH中保存了查找命令时需要遍历的目录, which 命令会在环境变量$PATH 设置的目录里查找符合条件的文件.也 ...

  5. 第六节 etc/passwd 、etc/shadow 、 useradd 、 groupadd

    调优方法原理:禁用atime的修改来节省cpu和内存资源.命令:mount noatime disk 1.配置文件1. /etc/passwd文档结构:由":" 分隔成7个字段&q ...

  6. Cleaner, more elegant, and wrong(翻译)

    Cleaner,more elegant,and wrong 整洁,更优雅,但是错的 并不是因为你看不到错误的产生路径就意味着它不存在. 下面是C#编程书中的一个片段,摘自关于异常处理的章节. try ...

  7. java 类的继承和接口的继承

    父类 public class person { String name; int age; void eat(){ System.out.println("吃饭"); } voi ...

  8. 聊聊API网关的作用

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 10.5px "Trebuchet MS" } p.p2 { margin: 0.0px ...

  9. Python列表操作

    自带帮助文档: >>> help(list) Help on class list in module builtins: class list(object) | list() - ...

  10. 自己封装的一个js方法用于获取显示的星期和日期时间

    自己封装的一个js方法用于获取显示的星期和日期时间 /** * 获取用于显示的星期和日期时间 * @param date * @returns {string} */ function getWeek ...