BestCoder Round #57 (div.2)1002
来源:互联网 发布:身份证号归属地数据库 编辑:程序博客网 时间:2024/05/18 03:59
Conturbatio
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 43 Accepted Submission(s): 21
Problem Description
There are many rook on a chessboard, a rook can attack the row and column it belongs, including its own place.
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
There are also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle will be attacked by any rook?
Input
The first line of the input is a integer T , meaning that there are T test cases.
Every test cases begin with four integersn,m,K,Q .
K is the number of Rook, Q is the number of queries.
ThenK lines follow, each contain two integers x,y describing the coordinate of Rook.
ThenQ lines follow, each contain four integers x1,y1,x2,y2 describing the left-down and right-up coordinates of query.
1≤n,m,K,Q≤100,000 .
1≤x≤n,1≤y≤m .
1≤x1≤x2≤n,1≤y1≤y2≤m .
Every test cases begin with four integers
Then
Then
Output
For every query output "Yes" or "No" as mentioned above.
Sample Input
22 2 1 21 11 1 1 22 1 2 22 2 2 11 11 22 1 2 2
Sample Output
YesNoYesHintHuge input, scanf recommended.
其实也是一个简单题;
这个题目最大的问题是在询问,每个询问要在O(logn)或O(1)时间完成
一开始以为是树状数组,当后来发现数组开不了那么大
询问那个矩形内是否会受到攻击,就是看它的每一行有一个车或它的每一列有一个车。
如果有就输出Yes,否者输出No
这样就很简单了,直接用两个数组标记那些行和列有车,然后得到其前缀和(用来判断它的每一行是否有一个车或每一列是否有一个车)
hang[i]表示前i行车的个数
lie[i]表示前i列车的个数
对于x1,y1,x2,y2这个矩形
只要判断hang[y2]-hang[y1-1] == y2-y1+1 和 lie[x2]-lie[x1-1] == x2-x1+1有一个成立就输出Yes否者输出No
0 0
- BestCoder Round #57 (div.2)1002
- BestCoder Round #57 (div.2)1001
- BestCoder Round #61 (div.2) 1002
- BestCoder Round #73 (div.2)1002/hdoj5631
- BestCoder Round #11 (Div. 2)
- BestCoder Round #11 (Div. 2)
- BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round 50 (div 2)
- BestCoder Round #50 (div.2)
- #BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round #54 (div.2)
- BestCoder Round #56 (div.2)
- BestCoder Round #58 (div.2)
- BestCoder Round #59 (div.2)
- BestCoder Round #59 (div.2)
- #BestCoder Round #59 (div.2)
- 竖直滚动 jquery 文字 图片
- java多线程之生产者消费者经典问题
- How to Take Ownership of a File/Folder Using Command-Line in Windows 7 or newer version System
- HDU 5480 杂题
- Linux Signal实现代码分析http://blog.csdn.net/suqin0802/article/details/8093004
- BestCoder Round #57 (div.2)1002
- 间隔动作函数
- 常用的四中聚类方法
- Linux内核模块指南(前言===>第三章完)。。。翻译完。。。
- arp攻击原理
- Learning code first day2015-09-26
- 寻找最近点对 编程之美2.11
- SQL经典问题1——产品、颜色、数量
- ArcGIS10.2 安装问题(win7 32位)