CF319E Ping-Pong 线段树 + vector + 思维
Code:
#include<bits/stdc++.h>
#define N 3000009
#define maxn 3000009
#define ll long long
#define lson ls[cur]
#define inf 1e9
#define rson rs[cur]
#define mid ((l+r)>>1)
using namespace std;
int read()
{
int x;
scanf("%d",&x);
return x;
}
void setIO(string s)
{
string in=s+".in";
string out=s+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
int rt,m,n,num,cnt,fa[maxn];
int pos[N], ls[N], rs[N];
struct node
{
int x,y;
node(int x=0,int y=0):x(x),y(y){}
}p[N];
vector<int>tr[maxn];
int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
void merge(int x,int y)
{
assert(x!=0);
p[y].x=min(p[y].x,p[x].x);
p[y].y=max(p[y].y,p[x].y);
fa[x]=y;
}
void add(int cur,int l,int r,int x,int y)
{
if(!cur) return;
for(int i=0;i<tr[cur].size();++i) merge(find(tr[cur][i]), y);
tr[cur].clear();
if(l==r) return;
if(x<=mid) add(lson,l,mid,x,y);
else add(rson,mid+1,r,x,y);
}
void Add(int &cur,int l,int r,int L,int R,int y)
{
if(L>R)return;
if(!cur)cur=++cnt;
if(L<=l&&R>=r)
{
tr[cur].push_back(y);
return;
}
if(L<=mid) Add(lson,l,mid,L,R,y);
if(R>mid) Add(rson,mid+1,r,L,R,y);
}
int main()
{
// setIO("input");
m=read();
for(int i=1;i<=m;++i)
{
int op=read(),x=read(),y=read();
if(op==1)
{
fa[++num]=num;
p[num]=node(x,y);
add(rt,-inf,inf,x,num), add(rt,-inf,inf,y,num);
if(p[num].x+1<p[num].y)
Add(rt,-inf,inf,p[num].x+1,p[num].y-1,num);
}
else
{
x=find(x),y=find(y);
if (x==y||(p[x].x<p[y].y&&p[x].x>p[y].x)||(p[x].y<p[y].y&&p[x].y>p[y].x)) puts("YES");
else puts("NO");
}
}
return 0;
}
CF319E Ping-Pong 线段树 + vector + 思维的更多相关文章
- [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...
- POJ 3928 Ping pong(树状数组)
Ping pong Time Limit: 1000MS ...
- LA4329 Ping pong(树状数组与组合原理)
N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...
- Ping pong(树状数组求序列中比某个位置上的数小的数字个数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Time Limit: 2000/1000 MS (Java/Others) ...
- 【BZOJ4184】shallot 线段树+vector+线性基
[BZOJ4184]shallot Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从 ...
- bzoj 4184 shallot 时间线建线段树+vector+线性基
题目大意 n个时间点 每个时间点可以插入一个权值或删除一个权值 求每个时间点结束后异或最大值 分析 异或最大值用线性基 但是线性基并不支持删除操作 我们可以对时间线建一棵线段树 离线搞出每个权值出现的 ...
- [CF653F] Paper task - 后缀数组,线段树,vector
[CF653F] Paper task Description 给定一个括号序列,统计合法的本质不同子串的个数. Solution 很容易想到,只要在传统统计本质不同子串的基础上修改一下即可. 考虑经 ...
- POJ 3928 & HDU 2492 Ping pong(树阵评价倒数)
主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...
- CodeForces - 786B Legacy (线段树+DIjkstra+思维)
题意:给N个点和Q条选项,有三种类型的选项:1.从u到v花费w修建一条路:2.从u到下标区间为[L,R]的点花费w修建一条路; 3.从下标区间为[L,R]的点到u花费w修建一条路. 然后求起点s到其余 ...
随机推荐
- [poj1363]Rails_模拟_栈
Rails poj-1363 题目大意:判断一个序列是否是1~n的合法出栈序列. 注释:$1\le n\le 10^4$. 想法:开始想到一种想法. 对于一段序列来讲,显然从首元素开始的连续小于尾元素 ...
- LA 3695 部分枚举
运用部分枚举的思想,很明显完全枚举点的思想是不可能的.改为枚举上下边界,当确定右边界j后,对左边界i,可以有点数为on[j]+on[i]+(leftu[j]-leftu[i])+leftd[j]-le ...
- 笔记本光驱位换SSD固态硬盘之硬盘格式化
笔记本光驱位换SSD固态硬盘之硬盘格式化 系列文章: ThinkPad E430c加装内存和SSD固态硬盘 笔记本光驱位换SSD固态硬盘之Ghost克隆原来的系统到SSD固态硬盘分区 概述 加装SSD ...
- Linuxpassword破解及grub加密演示
password破解及grub加密演示 so easy,不可不会! 原理: 通过进入单用户模式(单用户模式也即是仅仅有一个用户能够訪问资源的状态,且单用户模式就是系统处于最原始的状态,大部分服务还未开 ...
- 升级DM5校验
1,将某个文件生成带DM5的文件,使用srec_cat工具: read A #原始文件 srec_cat $A -o 要生成的文件名称 -Line_Length 46 -Address_Leng ...
- 卸载完百度影音以后天气助手还在,而且总是自己主动打开ie浏览器,解决方式
今天暴风影音不好用了.我就安装了百度影音,还有意外发现.相同的视频,用百度影音看不清楚,然后我就直接卸载了.结果卸掉以天气小助手还是在,而且总弹白色小框框,各种广告.最忍不了的是还自己主动打开ie浏览 ...
- 从零開始学Xamarin.Forms(二) 环境搭建、创建项目
一.环境搭建 Windows下环境搭建: 1.下载并安装jdk.Android SDK和NDK.当然还须要 VS2013 update 2(VS2010.VS2012均可)以上. a. 最新 ...
- vmware centos7 没有网络设备
vmware centos7 没有网络设备 选择VMware 虚拟机模拟器为CentOS 64 即可;
- javascript--给你的JS代码添加单元测试
通过测试框架为JavaScript应用添加测试,从而保证代码的高质量.这里的笔记例子应用在jaywcjlove/validator.js中. 安装 用到三个工具chai(断言工具),mocha(测试框 ...
- XML案例(使用JAXP进行SAX解析)
1.Book.java package cn.itcast.sax; public class Book { private String name; private String author; p ...