2019中山大学ACM校赛:二维前缀和二维差分

本文介绍了2019年中山大学程序设计竞赛中涉及二维前缀和与二维差分的问题。作者通过一道题目详细解释了如何使用二维前缀和快速判断监控区域是否能覆盖所有小偷活动区域,以及二维差分如何优化这个问题的解决方案,降低了时间复杂度。
摘要由CSDN通过智能技术生成

       最近碰到一道触及我知识盲区的题,对我来说是好题,所以趁热记下思路和学到的知识,希望从此之后这部分的知识会被我化为己用。

【写完我才发现我画的图里面的X,Y坐标轴标反了,标为X轴的应该是Y轴,标为Y轴的应该是X轴,不过问题不大】

2019年中山大学程序设计竞赛的一道题

Monitor

Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×mn×m.

But recently Xiaoteng found that his crops were often stolen by a group of people, so he decided to install some monitors to find all the people and then negotiate with them.

However, Xiao Teng bought bad monitors, each monitor can only monitor the crops inside a rectangle. There are pp monitors installed by Xiaoteng, and the rectangle monitored by each monitor is known.

Xiao Teng guess that the thieves would also steal qq times of crops. he also guessed the range they were going to steal, which was also a rectangle. Xiao Teng wants to know if his monitors can see all the thieves at a time.

Input

There are mutiple test cases.

Each case starts with a line containing two integers n,m(1≤n,1≤m,n×m≤107)n,m(1≤n,1≤m,n×m≤107) which represent the area of the land.

And the secend line contain a integer p(1≤p≤106)p(1≤p≤106) which represent the number of the monitor Xiaoteng has installed. This is followed by p lines each describing a rectangle. Each of these lines contains four intergers x1,y1,x2 and y2(1≤x1≤x2≤n,1≤y1≤y2≤m)x1,y1,x2 and y2(1≤x1≤x2≤n,1≤y1≤y2≤m) ,meaning the lower left corner and upper right corner of the rectangle.

Next line contain a integer q(1≤q≤106)q(1≤q≤106) which represent the number of times that thieves will steal the crops.This is followed by q lines each describing a rectangle. Each of these lines contains four intergers x1,y1,x2 and y2(1≤x1≤x2≤n,1≤y1≤y2≤m)x1,y1,x2 and y2(1≤x1≤x2≤n,1≤y1≤y2≤m) ,meaning the lower left corner and upper right corner of the rectangle.

Output

For each case you should print qq lines.

Each line containing YES or NO mean the all thieves whether can be seen.

Sample Input

6 6

3

2 2 4 4 

3 3 5 6

5 1 6 2

2

3 2 5 4

1 5 6 5

Sample output

YES

NO

下图是题目给的提示图,红色区域是监控范围,蓝色区域是小偷出现的区域。

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值