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 + 思维的更多相关文章

  1. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

  2. POJ 3928 Ping pong(树状数组)

                                                                          Ping pong Time Limit: 1000MS   ...

  3. LA4329 Ping pong(树状数组与组合原理)

    N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...

  4. Ping pong(树状数组求序列中比某个位置上的数小的数字个数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Ping pong Time Limit: 2000/1000 MS (Java/Others) ...

  5. 【BZOJ4184】shallot 线段树+vector+线性基

    [BZOJ4184]shallot Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从 ...

  6. bzoj 4184 shallot 时间线建线段树+vector+线性基

    题目大意 n个时间点 每个时间点可以插入一个权值或删除一个权值 求每个时间点结束后异或最大值 分析 异或最大值用线性基 但是线性基并不支持删除操作 我们可以对时间线建一棵线段树 离线搞出每个权值出现的 ...

  7. [CF653F] Paper task - 后缀数组,线段树,vector

    [CF653F] Paper task Description 给定一个括号序列,统计合法的本质不同子串的个数. Solution 很容易想到,只要在传统统计本质不同子串的基础上修改一下即可. 考虑经 ...

  8. POJ 3928 &amp; HDU 2492 Ping pong(树阵评价倒数)

    主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...

  9. CodeForces - 786B Legacy (线段树+DIjkstra+思维)

    题意:给N个点和Q条选项,有三种类型的选项:1.从u到v花费w修建一条路:2.从u到下标区间为[L,R]的点花费w修建一条路; 3.从下标区间为[L,R]的点到u花费w修建一条路. 然后求起点s到其余 ...

随机推荐

  1. ggplot画图笔记

    1.数据集相加符号 %+% 2.图形属性映射 aesc()函数 aes(x=mpg,y=wt)  把mpg属性映射为x,wt属性映射为y 图层图形属性可以添加.修改和删除映射. 如 3.位置调整参数 ...

  2. 如何快速恢复SLAVE从库上某几张表

    在日常工作中,同步报错是DBA遇到最多的一个问题,如果修复后发现还没有解决,通常的办法是在master上重新导入一份备份,然后在slave上恢复,这个方案是针对整个库不是很大的情况,那么如果是数据库比 ...

  3. N天学习一个linux命令之xz

    前言 最近使用gitbook写接口文档,gitbook需要nodejs执行环境.安装nodejs时,发现安装包使用的是xz后缀,它是使用LZMA无损数据压缩算法生成的文件,压缩率很高.GNU已经内置了 ...

  4. ORACLE11G 将dataguard的rman备份恢复到測试环境的单机oracle中的具体过程

    . 也就是说此时数据库仅仅能进行不全然恢复了,在打开数据库时得使用resetlogs打开. recover database until scn 11412370952; RMAN> recov ...

  5. javascript打开本地应用

    function openShell(){ if(window.ActiveXObject){ var cmd = new ActiveXObject('WScript.Shell') cmd.Run ...

  6. double x = 10 ,y = 0;y = x % 2; 这个表达式正确吗?

    The remainder function and % operator. 以下这段代码过不了编译的(gcc) #include <stdio.h> #include <fenv. ...

  7. Win8.1下COCOS2D-X 3.4环境搭建

     Cocos2dx_3.4开发环境搭建,并编译成APK 第一步:须要下载的:(windows64位系统下环境搭建) Ant   apache-ant-1.9.4-bin.zip NDK   and ...

  8. 1360 xth 的玫瑰花

    1360 xth 的玫瑰花  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 这天是rabbit 的生日 ...

  9. the user must supply a jdbc connection 错误解决方法

    转自:https://blog.csdn.net/actionzh/article/details/54200451 今天在配置hibernate之后,进行添加数据测试时,运行中报出了 the use ...

  10. 用JS将指定时间转化成用户当地时区的时间

    公司的项目是面向海外用户的,但是最初的设计没考虑到时差问题,存入数据库的时间都是东八区的时间,导致现在补救有点坑爹...... 有一个需求是,产品详细页需要注明此款产品的开售时间,当海外的用户来访问这 ...