VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可
先考虑第一种情况, 第二种类似,swap一下就可以了。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
inline int GetIdx(int l, int r){
return l + r | l != r;
}
int seg[maxn << ];
void update(int l, int r, int x, int d){
if (l == r){
seg[GetIdx(l, r)] = d;
return;
}
int mid = (l + r) >> ;
if (x <= mid){
update(l, mid, x, d);
}else{
update(mid+, r, x, d);
}
seg[GetIdx(l, r)] = min(seg[GetIdx(l, mid)], seg[GetIdx(mid+, r)]);
}
int query(int l, int r, int ua, int ub){
if (ua <= l && ub >= r){
return seg[GetIdx(l, r)];
}
int mid = (l + r) >> ;
int res = << ;
if (ua <= mid){
res = min(res, query(l, mid, ua, ub));
}
if (ub > mid){
res = min(res, query(mid+, r, ua, ub));
}
return res;
}
vector <int> line[maxn];
pair <int, int> rook[maxn << ], rec1[maxn << ], rec2[maxn << ];
bool ans[maxn << ];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n, m, k, q;
while (~scanf ("%d%d%d%d", &n, &m, &k, &q)){
for (int i = ; i < k; i++){
scanf ("%d%d", &rook[i].first, &rook[i].second);
}
for (int i = ; i < q; i++){
scanf ("%d%d%d%d", &rec1[i].first, &rec1[i].second, &rec2[i].first, &rec2[i].second);
}
for (int cas = ; cas <= ; cas++){
memset(seg, , sizeof seg);
for (int i = ; i <= n; i++){
line[i].clear();
}
for (int i = ; i < k; i++){
// 所有rook[i].first上的rook放入line里
line[rook[i].first].push_back(rook[i].second);
}
for (int i = ; i < q; i++){
//所有方格右边界线为rec2[i].first的放入line里
line[rec2[i].first].push_back(~i);
}
for (int i = ; i <= n; i++){
for (int j = ; j < line[i].size(); j++){
int tmp = line[i][j];
if (tmp < ){
tmp = ~tmp;
// 查找区间最值判断是否满足
if (query(, m, rec1[tmp].second, rec2[tmp].second) >= rec1[tmp].first){
ans[tmp] = true;
}
}else{
update(, m, tmp, i);
}
}
}
swap(n, m);
for (int i = ; i <k ;i++){
swap(rook[i].first, rook[i].second);
}
for (int i = ; i < q; i++){
swap(rec1[i].first, rec1[i].second);
swap(rec2[i].first, rec2[i].second);
}
}
for (int i = ; i < q; i++){
puts(ans[i] ? "YES" : "NO");
}
}
return ;
}
VK Cup 2015 - Round 1 -E. 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 ...
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...
- VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串
题目链接:http://codeforces.com/contest/533/problem/E E. Correcting Mistakes time limit per test 2 second ...
- Codeforces 524E Rooks and Rectangles 线段树
区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define ...
- VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...
- hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131 ...
随机推荐
- C#Socket编程socket.Connect权限出错问题及解决
最近使用Vs2010编写Socket程序,客户端在调用socket.Connect()时,总是出现: 请求“System.Net.SocketPermission, System, Version=4 ...
- android 如何解决模块之间的通讯的耦合问题
使用EventBus http://wuyexiong.github.io/blog/2013/04/30/android-fragment/ http://yunfeng.sinaapp.com/? ...
- power desinger 学习笔记<一>
如果一张表有 很多字段(多于30个),那么一个一个复制粘贴,耗时耗力.可以偷懒,事先编辑好 sql脚本,然后把sql脚本导入 power designer,是不是很方便? 看下面的 1. 打开Pow ...
- HttpClient的get+post请求使用
啥都不说,先上代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReade ...
- X-Plane数据交互
要用X-Plane进行二次开发,免不了需要进行参数的传递,下面我们来看看与X-Plane进行数据交互都有哪些方式. 与FSX和Flightgear基本一样,X-Plane支持插件,自然也支持通过插件进 ...
- Linux中的find指令
find find是最常见和最强大的查找命令,在磁盘中查找文件,用它找到任何你想找的文件,就是速度有点慢. find path -option [ -print ] [ ...
- const详解
详解C++中的const关键字
- C++中extern关键字使用(转)
参考文章:http://blog.csdn.net/sruru/article/details/7951019 chapter1.如何混合编译C语言和C++ 实际开发过程中,C++中会调用C与语言编写 ...
- 【ZOJ2112】【整体二分+树状数组】带修改区间第k大
The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...
- 【POJ3461】【KMP】Oulipo
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...