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 如果需要分别 ...
随机推荐
- Object.defineProperties()与Proxy对象代理
Object.defineProperties() 了不起啊..vue.js通过它实现双向绑定的 Object.defineProperties(obj,props) 方法直接在一个对象上定义新的属性 ...
- 如何抓取电商的数据 & Python
如何抓取电商的数据 & Python https://www.zhihu.com/question/40720286 https://www.zhihu.com/question/382455 ...
- php配置-解决大数据超多字段的POST方式提交无法完全接受的问题
例如:在盘点表的数据提交中出现了POST大量数据超多字段的将近2000个字段,部分字段没有接受:修改方法为修改php.ini 将max_input_var调大,该值默认为1000 max_input_ ...
- phonegap-plugin-contentsync
一.API 1.ContentSync.sync(options) options.src : 字符串类型 (必选项)远程托管内容的URL.更新一个生产环境下的APP,常使用HTTPS option ...
- KKT条件
kkt条件背下来容易.理解上还有问题 主要是lambda≥0和lambda*f(x)=0这两个条件懵逼. 下面说明一下为什么 参考:https://blog.csdn.net/newthinker_w ...
- 了解C#中的HashSet与示例
在C#中引入HashSet 在.NET框架中,有几个类可用于执行这些操作.一些课程如下: 列表 字典 哈希集 队列 集合 在C#编程中,像ArrayList,List这样的集合,只需添加其中的值,而不 ...
- webpack 配置 publicPath的理解
在学习webpack的时候,配置文件中有一个publicPath属性,一直不是很明白它到底是怎么用,也查了很多资料,得到最多的说法是当打包的时候,webpack会在静态文件路径前面添加publicPa ...
- codeforces484A
Bits CodeForces - 484A Let's denote as the number of bits set ('1' bits) in the binary representati ...
- BZOJ 1800 [Ahoi2009]fly 飞行棋
题目链接 思路 终于有一道自己想出来的题了,开心. 因为是矩形,一定有直角,所以考虑直径,之后由于矩形对角线是两条直径,所以考虑组合数. 直径有n条,矩形有c(n,2)个. #include<i ...
- http协议状态码大全
100 Continue:初始的请求已经接受,客户应当继续发送请求的其余部分. 101 Switching Protocols:服务器将遵从客户的请求转换到另外一种协议. 200 OK:一切正常, ...