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 ...
随机推荐
- outlook关闭时最小化工具
outlook本身不能支持设置点击关闭按钮时最小化,而是直接退出.需要借助一个加载项实现: Keep Outlook Running. Keep Outlook Running主页:https://s ...
- I2C和SPI总线对比
1 iic总线不是全双工,2根线SCL SDA.spi总线实现全双工,4根线SCK CS MOSI MISO 2 iic总线是多主机总线,通过SDA上的地址信息来锁定从设备.spi总线只有一个主设备, ...
- 大量界面刷新时手动Dispose也是有必要的
在winform窗体上拖一个flowLayoutPane,一个Button,项目中再创建一个用户控件UcControl,用户控件上放几十个子控件 private void button1_Click( ...
- bzoj4802 欧拉函数(附Millar-Rabin和Pollard-Rho讲解)
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4802 [题解] 参考:http://www.matrix67.com/blog/archiv ...
- luogu P2113 看球泡妹子
2333 这么水的蓝题 f[i][j] 表示看了i场比赛,小♀红的什么东西为j时小♂明的什么值 强行压维蛤蛤 剩下的转移很简单(注意i的循环顺序从后往前,01背包) (具体见代码) #include& ...
- nginx入门三
负载均衡 upstream upstream app_server { server 127.0.0.1:8000; server 192.168.2.134:80; server 47.xx.xx. ...
- MySQL— 进阶
目录 一.视图 二.触发器 三.函数 四.存储过程 五.事务 一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集 ...
- ansible报错Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this
安装和配置好ansible,执行命令时报错如下 [root@test01 ansible-install]# ansible test -m shell -a 'w' >> Using a ...
- python通过操作windows系统注册表方式修改环境变量
#coding=utf8 import os import sys from subprocess import check_call if sys.hexversion > 0x0300000 ...
- (记录合并)union和union all的区别
SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION内部的SELECT语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条SE ...