Codeforces 524E Rooks and Rectangles 线段树
区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m, k, q;
bool ans[N]; PII p[N];
struct Qus {
PII a, b;
bool operator < (const Qus& rhs) const {
return b < rhs.b;
}
int id;
} qus[N]; int a[N << ];
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
void update(int p, int val, int l, int r, int rt) {
if(l == r) {
a[rt] = max(a[rt], val);
return;
}
int mid = l + r >> ;
if(p <= mid) update(p, val, lson);
else update(p, val, rson);
a[rt] = min(a[rt << ], a[rt << | ]);
}
int query(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) return a[rt];
int mid = l + r >> ;
if(R <= mid) return query(L, R, lson);
else if(L > mid) return query(L, R, rson);
else return min(query(L, R, lson), query(L, R, rson));
} void solve() {
sort(p + , p + + k);
sort(qus + , qus + + q);
memset(a, , sizeof(a));
for(int i = , j = ; i <= q; i++) {
while(j <= k && p[j] <= qus[i].b) update(p[j].se, p[j].fi, , m, ), j++;
int mn = query(qus[i].a.se, qus[i].b.se, , m, );
if(mn >= qus[i].a.fi) ans[qus[i].id] = true;
}
} int main() {
scanf("%d%d%d%d", &n, &m, &k, &q);
for(int i = ; i <= k; i++) scanf("%d%d", &p[i].fi, &p[i].se);
for(int i = ; i <= q; i++) {
scanf("%d%d", &qus[i].a.fi, &qus[i].a.se);
scanf("%d%d", &qus[i].b.fi, &qus[i].b.se);
qus[i].id = i;
}
solve();
swap(n, m);
for(int i = ; i <= k; i++) swap(p[i].fi, p[i].se);
for(int i = ; i <= q; i++) {
swap(qus[i].a.fi, qus[i].a.se);
swap(qus[i].b.fi, qus[i].b.se);
}
solve();
for(int i = ; i <= q; i++) printf("%s\n", ans[i] ? "YES" : "NO");
return ;
} /*
*/
Codeforces 524E Rooks and Rectangles 线段树的更多相关文章
- VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值
E. Rooks and Rectangles Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemse ...
- VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- codeforces 22E XOR on Segment 线段树
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...
- Codeforces 588E. A Simple Task (线段树+计数排序思想)
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- Codeforces 444C DZY Loves Colors(线段树)
题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
随机推荐
- 由-webkit-transform-style:preserve-3d;所想
看一个用css3写幻灯片的demo用到了这么几个属性 .demo{ -webkit-transform-style:preserve-3d; -webkit-perspective:800px; -w ...
- 字符串数字转换成对应的Double数值
一,介绍 前面实现了字符串转换成整形数值.参考这里: 它不支持小数,不支持符号(正.负号) 现在实现一个更复杂一点字符串转换成数值的程序. 它支持“浮点字符串”转换成对应的浮点数值,如: " ...
- Spring中的Bean配置
IOC&DI概述 OPC(Inversion of Control):其思想是反转资源获取的方向.传统的资源查找方式要求组件向容器发起请求查找资源.作为回应,容器适时的返回资源.而应用了IOC ...
- luogu 2294 狡猾的商人 带权并查集
此题做法多啊 带权并查集,区间dp,前缀和,差分约束 1.自己写的前缀和, 11 #include<bits/stdc++.h> #define rep(i,x,y) for(regist ...
- UBUNTU18.04安装网易云音乐并直接图标启动
这是一个网友改的程序,安装好以后把 ~/.cache/netcase-cloud-music 这个目录删除掉,就可以正常使用了,不用root权限
- luogu P4082 [USACO17DEC]Push a Box
传送门 一个人推箱子,和之前的华容道中的棋子移动有异曲同工之妙,因为每次可以让人走到箱子的其他方向上,或者推一下箱子 所以状态可以设成\(f_{i,j,k}\),即箱子在\((i,j)\),人在\(k ...
- Python--Virtualenv简明教程
原文链接 http://www.jianshu.com/p/08c657bd34f1 virtualenv通过创建独立Python开发环境的工具, 来解决依赖.版本以及间接权限问题. 比如一个项目依赖 ...
- web前端最全各类资源
链接:http://www.sohu.com/a/157593700_132276
- 2、SpringBoot接口Http协议开发实战8节课(1-6)
1.SpringBoot2.xHTTP请求配置讲解 简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧 1.@RestController and @RequestMapping是 ...
- LOJ 2483: 洛谷 P4655: 「CEOI2017」Building Bridges
题目传送门:LOJ #2483. 题意简述: 有 \(n\) 个数,每个数有高度 \(h_i\) 和价格 \(w_i\) 两个属性. 你可以花费 \(w_i\) 的代价移除第 \(i\) 个数(不能移 ...