题意: 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. hibernate4.3.8整合struts2过程中遇到的问题

    1.遇到的异常: Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to ...

  2. 2016.7.13final 修饰符使用

    final修饰符可以修饰类.变量.函数: 1.被final所修饰的类不能被继承,函数不能被继承,成员变量不能再次被赋值并且被称为常量: 2.被final 修饰的成员变量 .它通常被static所修饰, ...

  3. SGU 135.Drawing Lines

    水题,不说了. #include <iostream> using namespace std; int f[70000]={1}; int n; int main(){ cin>& ...

  4. HTML5拖放API

    拖放事件事件提供了拖放可以控制几乎所有方面的拖放操作.棘手的部分是确定每个事件触发:在拖项目火:别人火下降的目标.拖动项时,以下事件(按照这个顺序): 拖曳开始拖dragend此刻你把鼠标按钮和开始移 ...

  5. Java包详解

    背景: 在java中要求文件名和类名相同,所以如果把多个类放在一起,就可能出现文件名冲突 所以用包来解决,一个包中可以包含多个类 包是java提供的一种用于区别类的名字空间的机制,是类的组织方式,是一 ...

  6. HDU2602 (0-1背包问题)

      N - 01背包 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descri ...

  7. 01:A+B问题

    总时间限制:  1000ms 内存限制:  65536kB 描述 在大部分的在线题库中,都会将A+B问题作为第一题,以帮助新手熟悉平台的使用方法. A+B问题的题目描述如下:给定两个整数A和B,输出A ...

  8. 得到某个进程所有线程ID和入口地址

    #include <windows.h> #include <tlhelp32.h> #include "iostream" using namespace ...

  9. js两个时间相减

    平常总会遇到需要算两个日期之间是多少天,以下是使用JavaScript算时间差多少天的: // 给日期类对象添加日期差方法,返回日期与diff参数日期的时间差,单位为天 Date.prototype. ...

  10. [151116 记录] 使用Python3.5爬取豆瓣电影Top250

    这一段时间,一直在折腾Python爬虫.已有的文件记录显示,折腾爬虫大概个把月了吧.但是断断续续,一会儿鼓捣python.一会学习sql儿.一会调试OpenCV,结果什么都没学好.前几天,终于耐下心来 ...