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. nyoj_212_K尾相等数_210402272239

    K尾相等数 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 输入一个自然数K(K>1),如果存在自然数M和N(M>N),使得K^M和K^N均大于等于100 ...

  2. 输入法InputConnection

    /**  * The InputConnection interface is the communication channel from an  * {@link InputMethod} bac ...

  3. HDU 4522

    DIJK,最短路,建两个图就好了. #include <cstdlib> #include <cstdio> #include <cstring> #include ...

  4. P​H​P​中​h​t​t​p​协​议​详​解

    对PHP文件来说 Php能够有  html   css javascript php脚本 flash它的不同部分是在不同的地方运行的(server和client) http协议 1. http协议是建 ...

  5. 安装 KB2844286 导致SharePoint 2010 XSLT web part 显示出现错误

    上周末给Windows 打完补丁后,周一在通过From SharePoint的方式插入图片时,出现了如下错误: Unable to display this Web Part. To troubles ...

  6. C语言编程入门——程序练习(上)

    大家能够敲写一下以下的练习代码.看下执行结果,都非常easy.关键要理解. if: # include <stdio.h> int main(void) { int i = 1; i = ...

  7. sql server 2008安装图解

    本篇文章介绍了安装SQL Server 2008企业版的软硬件配置要求,安装过程的具体步骤,以及须要注意的事项. 步骤/方法 1 在这里我们将用图解的方式.来介绍SQL Server 2008安装和配 ...

  8. Spring为了简化java开发採用的四种策略

    以下是<Spring in action>中的总结性语言,记录下来,作为研究源码的主要线索. 1.採用轻量级的pojo.最小侵入式编程. 2.依赖注入(DI)和面向接口编程实现松耦合. 3 ...

  9. AndroidUI组件之ActionBar

    有一段时间没有写博文了,发现自己的博文的完整度不是非常好.就拿AndroidUI组件这一块.一直没有更新完.我会尽快更新.好了.不多说了,今天来看一下ActionBar. 依照以往的作风.知识点都以代 ...

  10. 源码中修改Android的开机画面和动画【转】

    本文转载自:http://blog.csdn.net/dddxxxx/article/details/54343976 参照文章:http://blog.csdn.net/a345017062/art ...