Codeforces Round #524 (Div. 2) F. Katya and Segments Sets(主席树)
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(主席树)的更多相关文章
- Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...
- Codeforces Round #524 (Div. 2) F
题解: 首先这个东西因为强制在线区间查询 所以外面得套线段树了 然后考虑几条线段怎么判定 我们只需要按照右端点排序,然后查询的时候查找最右节点的前缀最大值就可以了 然后怎么合并子区间信息呢 (刚开始我 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)
题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...
- 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 ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
随机推荐
- 模板】AC自动机(简单版)
模板]AC自动机(简单版) https://www.luogu.org/problemnew/show/P3808 这是一道简单的AC自动机模板题. 用于检测正确性以及算法常数. 为了防止卡OJ,在保 ...
- POJ 2396 Budget(有源汇上下界网络流)
Description We are supposed to make a budget proposal for this multi-site competition. The budget pr ...
- [剑指Offer]62-圆圈中最后剩下的数(约瑟夫环问题)(法二待做)
题目链接 https://www.nowcoder.com/practice/f78a359491e64a50bce2d89cff857eb6?tpId=13&tqId=11199&t ...
- 破解myeclipse 2014
用网上的教程的确可以,但是他似乎写的有点少.....试了很多次,说说他少的: http://jingyan.baidu.com/article/fdbd42771039bfb89e3f4838.htm ...
- 802.1X技术介绍
1.802.1X IEEE802 LAN/WAN委员会为解决无线局域网网络安全问题,提出了802.1X协议.后来,802.1X协议作为局域网端口的一个普通接入控制机制在以太网中被广泛应用,主要解决以太 ...
- c#调用dll接口传递utf-8字串方法
1. 起源: VCU10之视频下载模块,采用纯python编码实现,c++代码调用pythonrun.h配置python运行环境启动python模块,编译为dll给c#调用,以使界面UI能够使用其中功 ...
- redis集群 与spring-data-redis 集成
所遇到的坑:必须使用如下的jedis 版本与spring-data-redis 版本,才能够达到集群效果 .1.7版本以前是不支持集群的 <dependency> <groupId& ...
- samrty模板变量操作符
count_sentences [计算句数],示例:{$smarty.get.name|count_sentences} count_words [计算词数],示例:{$smarty.get.name ...
- [z] Git pull 强制覆盖本地文件
git fetch --all git reset --hard origin/master git pull git fetch 只是下载远程的库的内容,不做任何的合并 git reset 把HEA ...
- 9.26 H5日记
9.26 1.新的背景属性,background-position background-position有两个值,水平和垂直,单位px ❤在html和CSS当中,有三个属性可以向服务器发送请求,分别 ...