【HDU - 6514】Monitor(二维差分,前缀和)

题干:

Monitor

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 163840/163840 K (Java/Others)
Total Submission(s): 872    Accepted Submission(s): 145

Problem Description

Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×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 p monitors installed by Xiaoteng, and the rectangle monitored by each monitor is known. 

Xiao Teng guess that the thieves would also steal q 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) which represent the area of the land.

And the secend line contain a integer 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) ,meaning the lower left corner and upper right corner of the rectangle.

Next line contain a integer 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),meaning the lower left corner and upper right corner of the rectangle.

Output

For each case you should print q 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

Hint

In the picture,the red solid rectangles mean the monitor Xiaoteng installed, and the blue dotted rectangles mean the area will be stolen.

题目大意:

   给你p个红色矩形局域,再给你q次询问(每次一个蓝***域),每次问你能否蓝***域被红***域完全覆盖。

解题报告:

   考虑暴力的做法,对于每一个红***域,每一行都做标记差分,这样预处理的复杂度是O(pn),显然会T,考虑优化掉这个n,那就是进行第二次差分,最后就可以得到真值(每一个点被覆盖的次数)。然后xjb搞一下答案就可以了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
int n,m,p,q;
int main()
{
	while(~scanf("%d%d",&n,&m)) { 
		vector<vector<ll> > vv(m+14,vector<ll>(n+14,0));
		vector<vector<ll> > sum(m+14,vector<ll>(n+14,0));
		scanf("%d",&p);
		for(int x1,x2,y1,y2,i = 1; i<=p; i++) {
			scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
			vv[x1][y1]++;
			vv[x1][y2+1]--;
			vv[x2+1][y1]--;
			vv[x2+1][y2+1]++;
		}
		for(int i = 1; i<=n; i++) {
			for(int j = 1; j<=m; j++) {
				vv[j][i] += vv[j-1][i];
			}
		}
		for(int i = 1; i<=m; i++) {
			for(int j = 1; j<=n; j++) {
				vv[i][j] += vv[i][j-1];
			}
		}
		for(int i = 1; i<=m; i++) {
			for(int j = 1; j<=n; j++) {
				if(vv[i][j] >= 1) vv[i][j] = 1;
				else vv[i][j] = 0;
			}
		}
		for(int i = 1; i<=m; i++) {
			for(int j = 1; j<=n; j++) {
				sum[i][j] = vv[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
			} 
		}
		scanf("%d",&q);
		while(q--) {
			int x1,x2,y1,y2;
			scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
			ll tmp = sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];
			if(tmp == 1LL*(x2-x1+1)*(y2-y1+1)) puts("YES");
			else puts("NO");
		}
	} 


	return 0 ;
}

 

全部评论

相关推荐

来个厂收我吧:首先,市场侧求职我不是很懂。 但是,如果hr把这份简历给我,我会觉得求职人不适合做产品经理。 问题点: 1,简历的字体格式不统一,排版不尽如人意 2,重点不突出,建议参考star法则写个人经历 3,印尼官方货币名称为印度尼西亚卢比(IDR),且GMV690000印尼盾换算为305人民币,总成交额不高。 4,右上角的意向职位在发给其他公司时记得删除。 5,你所有的经历都是新媒体运营,但是你要投市场营销岗位,jd和简历不匹配,建议用AI+提示词,参照多个jd改一下经历内容。 修改建议: 1,统一字体(中文:思源黑体或微软雅黑,英文数字:time new romans),在word中通过表格进行排版(b站学) 2,校招个人经历权重:实习经历=创业经历(大创另算)>项目经历>实训经历>校园经历 3,请将项目经历时间顺序改为倒序,最新的放最上方。 4,求职方向不同,简历文字描述侧重点也需要不同。
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务