https://codeforces.com/contest/1080/problem/F

题意

有k个区间,区间的种类有n种,有m个询问(n,m<=1e5,k<=3e5),每次询问a,b,x,y,代表对于种类编号为[a,b]的每一种区间,是否都存在一个区间x<=l,r<=y,输出yes or no

思路

  • 现将区间按左端点从小到大排序,对于每一个询问首先找出第一个左端点大于x的区间,然后看[a,b]中最大的右端点是否>y即可
  • 需要一颗以种类编号为下标,右端点为权值的主席树,维护种类[a,b]的最大右端点值
  • 假如找出了第一个左端点大于x的区间,怎么知道后面的区间的左端点一定<=y?
    • 因为每个种类上的点记录的是本种类点的最小右端点,假如左端点>y,则这个区间的右端点一定大于>y,所以不用担心这一类区间会被计算在内
  • 怎么保证本种类左端点>=x的区间,最小的右端点一定>=x?
    • 排好序后,反着建树
#include<bits/stdc++.h>
#define M 300005
#define inf 0x3f3f3f3f
using namespace std;
int st[M],ma[M],rt[M*40],ls[M*40],rs[M*40],vl[M*40];
int pos,n,m,k,i,a,b,x,y,cnt,ans;
struct N{
int l,r,p;
}p[M];
bool cmp(N a,N b){
return a.l<b.l;
}
void ud(int pre,int &o,int l,int r,int pos,int val){
if(pre==o){o=++cnt;ls[o]=ls[pre];rs[o]=rs[pre];}
if(l==r){vl[o]=val;return;}
int mid=(l+r)/2;
if(pos<=mid)ud(ls[pre],ls[o],l,mid,pos,val);
else ud(rs[pre],rs[o],mid+1,r,pos,val);
vl[o]=max(vl[ls[o]],vl[rs[o]]);
} int qy(int o,int l,int r,int L,int R){
int mid=(l+r)/2;
if(!o)return inf;
if(L<=l&&r<=R)return vl[o];
if(R<=mid)return qy(ls[o],l,mid,L,R);
if(L>mid)return qy(rs[o],mid+1,r,L,R);
return max(qy(ls[o],l,mid,L,R),qy(rs[o],mid+1,r,L,R));
} int main(){
cin>>n>>m>>k;
memset(ma,inf,sizeof(ma));vl[0]=inf;
for(i=1;i<=k;i++)scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].p);
sort(p+1,p+k+1,cmp);
for(i=1;i<=k;i++)st[i]=p[i].l;
st[k+1]=inf;
for(i=k;i>=1;i--){
rt[i]=rt[i+1];
if(ma[p[i].p]>p[i].r){
ud(rt[i+1],rt[i],1,n,p[i].p,p[i].r);
ma[p[i].p]=p[i].r;
}
} for(i=0;i<m;i++){
scanf("%d%d%d%d",&a,&b,&x,&y);
pos=lower_bound(st+1,st+k+2,x)-st;
if(pos==k+1)ans=inf;
else ans=qy(rt[pos],1,n,a,b);
if(ans<=y)printf("yes\n");else printf("no\n");
fflush(stdout);
}
}

Codeforces Round #524 (Div. 2) F. Katya and Segments Sets(主席树)的更多相关文章

  1. Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)

    https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...

  2. Codeforces Round #524 (Div. 2) F

    题解: 首先这个东西因为强制在线区间查询 所以外面得套线段树了 然后考虑几条线段怎么判定 我们只需要按照右端点排序,然后查询的时候查找最右节点的前缀最大值就可以了 然后怎么合并子区间信息呢 (刚开始我 ...

  3. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  4. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

  5. Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)

    题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...

  6. Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树

    E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consi ...

  7. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  8. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  9. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

随机推荐

  1. UVa 548 Tree(二叉树最短路径)

    You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...

  2. Windows Server RRAS 配置

    在Windows Server上,RRAS 是 Rounting and Remote Access Service 的简称. 通过 RRAS UI 管理器可实现 VPN 和 NAT 的配置. RRA ...

  3. Android的事件分发机制

    public boolean dispatchTouchEvent(MotionEvent event) 通过方法名我们不难猜测,它就是事件分发的重要方法.那么很明显,如果一个MotionEvent传 ...

  4. undefined reference to...

    wj@wj-Inspiron-:~/Downloads/LBD_Descriptor/build$ cmake .. -- Configuring done -- Generating done -- ...

  5. C# Request.RawUrl与Request.Url的区别

    RawUrl——不包含域名及端口的地址 Url——包含域名,最全

  6. Jmeter分布测试

    一.负载机为Linux Linux上安装Jmeter 1.Windows中jmeter整个安装目录copy至Linux /usr/local/autodeploy目录 ps.使用winSCP工具cop ...

  7. Selenium+PhantomJS

    Selenium Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,类型像我们玩游戏用的按键精灵,可以按指定的命令自动操作,不同是Selenium 可以直接运行在浏览器上, ...

  8. [Robot Framework] 学习资料

    https://www.cnblogs.com/pachongshangdexuebi/category/981644.html Robot Framework学习笔记(一)------环境搭建 Ro ...

  9. 各种编译不通过xcode

    2017-08-24 Apple Mach-O Linker (Id) Error Linker command failed with exit code 1 (use -v to see invo ...

  10. android模拟器不能上网设置

    进行sdk目录中的platform-tools目录: adb devices 系统会罗列出所有设置 adb -s emulator- shell 最后设置网关 setprop net.dns1 192 ...