CF1080F Katya and Segments Sets
题意:给定n个区间,每个区间有颜色。m次询问,每次询问:这n个区间中所有被包含在[x, y]这一区间中的区间,它们的颜色是否取遍了[l, r]中的所有颜色。
强制在线。
解:第一步是大家都熟悉的套路⑧,把这些区间按照左端点排序。
然后从右往左加区间,用一个可持久化数据结构维护答案。
然后我在这里就被套路住了......一般来说是线段树上x维护右端点为x的答案。但是本题要把第二维换一下。
主席树的版本仍旧是左端点。但是线段树上每个位置维护的是该颜色的区间,结尾的最小值。
然后查询,我们就查对应版本对应颜色区间的全体最大值是否大于y。大于y表示那个颜色无解。输出no。否则输出yes。
#include <bits/stdc++.h>
const int N = , M = , INF = 0x7f7f7f7f;
struct Node {
int l, r, c;
inline bool operator <(const Node &w) const {
return l < w.l;
}
}node[N];
int ls[M], rs[M], large[M], tot;
int xx, q, n, lm, X[N], rt[N];
void insert(int &x, int y, int p, int v, int l, int r) {
if(!x || x == y) {
x = ++tot;
ls[x] = ls[y];
rs[x] = rs[y];
large[x] = large[y];
}
if(l == r) {
large[x] = std::min(large[x], v);
return;
}
int mid = (l + r) >> ;
if(p <= mid) insert(ls[x], ls[y], p, v, l, mid);
else insert(rs[x], rs[y], p, v, mid + , r);
large[x] = std::max(large[ls[x]], large[rs[x]]);
//printf("[%d %d] large = %d \n", l, r, large[x]);
return;
}
int ask(int L, int R, int l, int r, int o) {
if(!o) return INF;
if(L <= l && r <= R) return large[o];
int mid = (l + r) >> , ans = -INF;
if(L <= mid) ans = std::max(ans, ask(L, R, l, mid, ls[o]));
if(mid < R) ans = std::max(ans, ask(L, R, mid + , r, rs[o]));
return ans;
}
int main() {
memset(large, 0x7f, sizeof(large));
scanf("%d%d%d", &lm, &q, &n);
for(int i = ; i <= n; i++) {
scanf("%d%d%d", &node[i].l, &node[i].r, &node[i].c);
X[i] = node[i].l;
}
std::sort(node + , node + n + );
std::sort(X + , X + n + );
xx = std::unique(X + , X + n + ) - X - ;
for(int i = n; i >= ; i--) {
node[i].l = std::lower_bound(X + , X + xx + , node[i].l) - X;
/// build
insert(rt[node[i].l], rt[node[i].l + ], node[i].c, node[i].r, , lm);
//printf("insert %d %d rt[%d] \n", node[i].c, node[i].r, node[i].l);
}
/*printf("X : ");
for(int i = 1; i <= xx; i++) {
printf("%d ", X[i]);
}
puts("");*/
for(int i = , x, y, l, r; i <= q; i++) {
scanf("%d%d%d%d", &l, &r, &x, &y);
int t = std::lower_bound(X + , X + xx + , x) - X;
//printf("i = %d t = %d \n", i, t);
if(t > xx) {
printf("no\n");
//printf("ERROR 1 \n");
}
else {
t = ask(l, r, , lm, rt[t]);
if(t > y) printf("no\n");
else printf("yes\n");
//printf("t = %d \n", t);
}
fflush(stdout);
}
return ;
}
AC代码
CF1080F Katya and Segments Sets的更多相关文章
- 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 ...
- 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) Solution
A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...
- [UCSD白板题] Covering Segments by Points
Problem Introduction You are given a set of segments on a line and your goal is to mark as few point ...
- POJ 1436 Horizontally Visible Segments (线段树·区间染色)
题意 在坐标系中有n条平行于y轴的线段 当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交 就视为它们是可见的 问有多少组三条线段两两相互可见 先把全部线段存下来 并按x ...
- 【37%】【poj1436】Horizontally Visible Segments
Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5200 Accepted: 1903 Description There ...
- TSQL 分组集(Grouping Sets)
分组集(Grouping Sets)是多个分组的并集,用于在一个查询中,按照不同的分组列对集合进行聚合运算,等价于对单个分组使用“union all”,计算多个结果集的并集.使用分组集的聚合查询,返回 ...
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- grouping sets从属子句的运用
grouping sets主要是用来合并多个分组的结果. 对于员工目标业绩表'businessTarget': employeeId targetDate idealDistAmount 如果需要分别 ...
随机推荐
- RedHat Enterprise Linux 6.4使用yum安装出现This system is not registered to Red Hat Subscription Management
我虚拟机安装的系统是RedHat Enterprise Linux 6.4-i686,是32位的.使用yum命令安装软件时候出现以下错误: This system is not registered ...
- Golang的select多路复用以及channel使用实践
看到有个例子实现了一个类似于核弹发射装置,在发射之前还是需要随时能输入终止发射. 这里就可以用到cahnnel 配合select 实现多路复用. select的写法用法有点像switch.但是和swi ...
- java 中 Math类
package cn.liuliu.com; import java.math.BigDecimal; import java.math.BigInteger; /* * 一.Math类? * * 1 ...
- python 读取csv 数据并画图分析
数据源 : https://pan.baidu.com/s/1eR593Uy 密码: yqjh python环境 python3 #encoding: utf-8 import csv impo ...
- Java反射和注解
反射:http://blog.csdn.net/liujiahan629629/article/details/18013523 注解:http://www.cnblogs.com/peida/arc ...
- 天虎云商wap和微信话项目总结
1:架构:以后要采用项目分模块的方式写代码了,不能写一个公用的controller包,每个模块分包,分别建立service,dao,但是模块同级的有个功能的baseDao, BaseSe ...
- 创建一个UWP 打包签名
Create a certificate for package signing 2017/2/8 3 min to read [ Updated for UWP apps on Windows 10 ...
- c++ 实现拓扑排序
要简洁大方地实现拓扑排序,首先要了解两个标准模板 std::queue 和 std::vector 1 queue 添加头文件 #include<queue> 定义一个int类型的队列 q ...
- BZOJ2658 ZJOI2012 小蓝的好友(treap)
显然转化为求不包含关键点的矩形个数.考虑暴力,枚举矩形下边界,求出该行每个位置对应的最低障碍点高度,对其建笛卡尔树,答案即为Σhi*(slson+1)*(srson+1),即考虑跨过该位置的矩形个数. ...
- POJ2763-Housewife Wind-树上单点修改区间求和
这道题可以树链剖分做.但是最近在给学弟搞数据结构复习了LCA树状数组RMQ 然后就搞了一发LCA+树状数组维护. dis数组维护当前点到根节点的权值和.则dis(u,v) = dis[u]+dis[v ...