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. Angular之输入输出属性

    一 父组件 company.component.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: ...

  2. linux ubuntu 18.04 无线网卡 rtl8821ce的安装

    解压rtl8821ce.zip 修改makefile,在shell中输入pwd,查看当前文件的路径,之后在Makefile中查找export Topdir ?=  /home/zzm/Download ...

  3. 前端框架(kraken、Express、Node、MVC)

    You know my loneliness is only kept for you, my sweet songs are only sang for you. 前端框架相关知识记录. krake ...

  4. 【python中单链表的实现】——包括初始化、创建、逆序、遍历等

    # coding=utf-8 class mynode(object): def __init__(self, data, nextnode = None): self.data = data sel ...

  5. [codeforces_597B] Restaurant(贪心)

    题目链接 http://codeforces.com/problemset/problem/597/B 题意 输入:区间数目n.及n个区间的起止(左闭右闭). 输出:最多不重叠的区间有多少个. 思路 ...

  6. sqlserver还原数据库失败,sql2008备份集中的数据库备份与现有的xxx数据库不同

    正常操作发现报标题错误,百度后解决思路如下(@参考文章)转到选项下面,勾选覆盖现有数据库即可

  7. Ansible Playbook 详解

    一.playbook 的简单使用 1.创建文件实例 (1)编辑配置文件 [root@tiejiangSRC1 ~]# cd /etc/ansible/ [root@tiejiangSRC1 ansib ...

  8. Winrar发现损坏的压缩文件头

    解决方法: 点击"解压到"-->保留损坏文件

  9. .net中几个经常用到的字符串的截取

    string str="123abc456";int i=3;1 取字符串的前i个字符   str=str.Substring(0,i); // or  str=str.Remov ...

  10. pyton random 模块

    import random print(random.random())#(0,1)----float 大于0且小于1之间的小数 print(random.randint(1,3)) #[1,3] 大 ...