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 如果需要分别 ...
随机推荐
- eclipse打开package explorer视图
第一步:window-show view-other 第二步:
- js 首次进入弹窗
今天有个需求,首次进入需要弹窗,然后就在网上找了下,虽然看了很多但是说的都不是我想要的,最后终于到了一个合适的. function get_cookie(Name) { var search = Na ...
- kibana——es的批量操作
一·_mget: 1.创建的索引如下: 2.批量查询: #查询两个 GET _mget { "docs":[ { "_index":"testdb&q ...
- mvn clean compile package install deploy
(1) package 目的是打包,在pom中,如果是jar就会打包成jar,如果是war就会打包成war 在pom.xml中: <modelVersion></modelVersi ...
- web攻擊
一.dos攻擊 向服務器發送數量龐大的合法數據,讓服務器分不清是不是正常請求,導致服務器接收所有的請求.海量的數據請求會使得服務器停止服務和拒絕服務. 防禦:阿里云或其它資源服務器有專門web應用防火 ...
- vue循環語句
迭代數組: v-for="site in sites”,sites表示源數組名,site表示數組元素: 迭代對象: v-for=“value in Object”, v-for=" ...
- TP5上传图片
模板: <form action="{:url('Temp/addTempDo')}" enctype="multipart/form-data" met ...
- 为WebRTC 应用部署Turn Server
部署WebRTC 或 SIP p2p 方案时经常会遇到p2p 无法穿透的环境, 这时就是TunServer 的用武之地了. 这里我们使用turnserver-0.7.3 下载confuse依赖库 wg ...
- 【C/C++】实现牛顿迭代
#include<bits/stdc++.h> using namespace std; /*(x+2)^2 +1 -2(x-1)^2+7 */ double f(double x){ - ...
- django--orm关系字段(ForeignKey、OneToOneField、ManyToManyField)详解
django中的关系字段 1.ForeignKey字段,即外键字段,对应一对多的情况,列如:一本书对应一个出版社,一个出版社可对应多本书. 2.ManyToManyFiled字段,即多对多字段,对应数 ...