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. spring boot开发REST接口

    1.配置pom.xml文件的<parent>和<depencencies>,指定spring boot web依赖 <parent> <groupId> ...

  2. N天学习一个linux命令之ip

    用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { CO ...

  3. 977. Squares of a Sorted Array

    题目描述: Given an array of integers A sorted in non-decreasing order, return an array of the squares of ...

  4. lzugis——Arcgis Server for JavaScript API之自己定义InfoWindow

    用过Arcgis Server for JavaScript API肯定知道InfoWIndow.你在用InfoWindow的时候会发现各种问题,比如不能全然显示的问题,遮盖对象的问题等等.所以呢我在 ...

  5. object-c 不定參数的遍历和原理

    object-c接收随意类型的參数: /** * 接收String类型的多个參数 * @param firsParam 第一个參数 */ -(void)TestString:(NSString*)fi ...

  6. C语言函数--H

    函数名: harderr 功 能: 建立一个硬件错误处理程序 用 法: void harderr(int (*fptr)()); 程序例: /*This program will trap disk ...

  7. Manacher求最长回文

    #1032 : 最长回文子串 时间限制:1000ms 单点时限:1000ms 内存限制:64MB 描写叙述 小Hi和小Ho是一对好朋友.出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助 ...

  8. CreateWindowEx和CreateWindow的区别

    CreateWindowEx 函数功能:该函数创建一个具有扩展风格的重叠式窗口.弹出式窗口或子窗口,其他与 CreateWindow函数相同.关于创建窗口和其他参数的内容,请参看CreateWindo ...

  9. Dubbo实战(一)高速入门

    Dubbo是什么? Dubbo[]是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. 其核心部分包含: 远程通讯: 提供对多种基于长连接的NIO框架抽象封 ...

  10. Java-MyBatis:MyBatis

    ylbtech-Java-MyBatis:MyBatis 1.返回顶部 1. MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foun ...