题意: 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 线段树最值+扫描线的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串

    题目链接:http://codeforces.com/contest/533/problem/E E. Correcting Mistakes time limit per test 2 second ...

  6. Codeforces 524E Rooks and Rectangles 线段树

    区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. sql根据'/'截取最后的字符串

    filpath字段值:/DataFile/UpLoad/Logo/NoPhoto.jpg select filpath,REVERSE((SUBSTRING(REVERSE(FilPath),0,CH ...

  2. HTML5 autocomplete属性、表单自动完成

    autocomplete属性 1.定义autocomplete属性规范表单是否启用自动完成功能.自动完成允许浏览器对字段的输入,是基于之前输入的值.2.应用范围autocomplete使用<fo ...

  3. 拦截器getmodel方法什么时候被调用(没搞懂有什么鸟用,自己搭的项目中用到了这个)

    拦截器是Struts2最强大的特性之一,它是一种可以让用户在Action执行之前和Result执行之后进行一些功能处理的机制.Struts2 的预定义拦截器 modelDriven 如果action实 ...

  4. Missing iOS Distribution signing identity问题解决

    问题描述 打包上传APPStore  Xcode报以下错误:Missing iOS Distribution signing identity for XXXXXX 查看证书后发现,Develop证书 ...

  5. Ubuntu 12.04下解决Rhythmbox Music Player乱码问题

    1.打开终端输入如下信息: $ sudo gedit ~/.profile 2.在打开的文档末尾加上如下两句: export GST_ID3_TAG_ENCODING=GBK:UTF-8:GB1803 ...

  6. SGU 115.Calendar

    连水3道,还能更水么... #include <stdio.h> using namespace std; ] = {, , , , , , , , , , , , }; int n, m ...

  7. Windows的命令行怎么支持通配符

    摸索出一个小技巧,虽然Windows的命令行本身不支持通配符,但可以在脚本里把传进来的参数当通配符用 只要加上@ARGV = glob "@ARGV";就行了 @ARGV = gl ...

  8. PHPCMS V9 学习总结(转)

    转自:http://www.cnblogs.com/Braveliu/p/5074930.html 在实现PHPCMS网站过程中,根据业务需求,我们遇到很多问题,特此总结如下,以便大家参考学习. [1 ...

  9. (转载)css垂直水平居中的整理

    方法一 .demo1 { width:180px; height:180px; line-height:180px; *font-size:160px; border:1px solid #ddd; ...

  10. 面试后 follow up letter 分享

    分享一下最近面试外企的follow up letter. Dear Mr. Xu,     Thank you again for the time you and Mr. Guo spent wit ...