【二维差分】Monitor

Monitor

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6514

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


 

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.

 

题目大意:

有多组输入,对于每一组输入,先输入两个个整数n,m,其下一行是一个整数p,下面p行每行输入四个整数x1,y1,x2,y2,代表着从(x1,y1)到(x2,y2)这一矩形区域被全部标记,然后输入一个整数q,其下q行,每行输入四个整数x1,y1,x2,y2,如果矩形区域(x1,y1)到(x2,y2)这整个矩形均被标记,则输出YES,否则输出NO.

解题思路:

我们可以在图中将所有被标记过的矩形区域里面的数全部置为1,然后求一下面积的前缀和,在查询过程中,只需根据面积前缀和求出这一区域的面积,若求出的面积与该矩形的实际面积相同,则证明这一区域被全部覆盖,因此,在每一次输入覆盖区域时,我们可以通过类似差分的思想,将mapp[x1][y1],mapp[x2+1][y2+1]都加上一,将mapp[x1][y2+1],mapp[x2+1][y1]均减去一,然后求整个区域的和,对于那些mapp[i][j]>1,将其置为1,方便后面求面积的前缀和,最后求一下面积的前缀和,查询即可。注:此题数组范围不确定,只能根据n,m的值来开空间,否则会内存超限。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
/*vector<int> mapp[10000010];
*/int main() 
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int n,m;while(scanf("%d %d",&n,&m)!=EOF) {/*rep(i,0,n+1) {mapp[i].clear();rep(j,0,m+1) {mapp[i].push_back(0);}}*/int **mapp;mapp=(int**)malloc(sizeof(int*)*(n+10));rep(i,0,n+1) mapp[i]=(int*)malloc(sizeof(int)*(m+10));rep(i,0,n+1) rep(j,0,m+1) mapp[i][j]=0;int p;int x1,x2,y1,y2;scanf("%d",&p);rep(i,1,p) {scanf("%d %d %d %d",&x1,&y1,&x2,&y2);mapp[x1][y1]++;mapp[x2+1][y2+1]++;mapp[x1][y2+1]--;mapp[x2+1][y1]--;}rep(i,1,n) {rep(j,1,m) {mapp[i][j]=mapp[i][j]+mapp[i-1][j]+mapp[i][j-1]-mapp[i-1][j-1];}}rep(i,1,n) {rep(j,1,m) {if(mapp[i][j]) mapp[i][j]=1;}}rep(i,1,n) {rep(j,1,m) {mapp[i][j]=mapp[i][j]+mapp[i-1][j]+mapp[i][j-1]-mapp[i-1][j-1];}}int q;scanf("%d",&q);rep(i,1,q) {scanf("%d %d %d %d",&x1,&y1,&x2,&y2);int ans=mapp[x2][y2]-mapp[x1-1][y2]-mapp[x2][y1-1]+mapp[x1-1][y1-1];if(ans==(x2-x1+1)*(y2-y1+1)) printf("YES\n");else printf("NO\n");}}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/536295.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【二分+二维前缀和】Largest Allowed Area

Largest Allowed Area 时间限制: 1 Sec 内存限制: 128 MB 提交: 146 解决: 54 [提交] [状态] [命题人:admin] 题目描述 A company is looking for land to build its headquarters. It has a lot of money and can buy as many land patches as it needs. Its goal, howev…

【数学】Floating-Point Hazard

Floating-Point Hazard 时间限制: 1 Sec 内存限制: 128 MB 提交: 106 解决: 42 [提交] [状态] [命题人:admin] 题目描述 Given the value of low, high you will have to find the value of the following expression: If you try to find the value of the above express…

【线段树】Segment Tree

Segment Tree 时间限制: 1 Sec 内存限制: 512 MB 提交: 107 解决: 23 [提交] [状态] [命题人:admin] 题目描述 Mcginn opens the code which he wrote 25 years ago. Clever Mcginn wants to know how many positive interger n satisfied that the maximum c can reach w…

扶桑号战列舰【RMQ+分治】

扶桑号战列舰 时间限制: 1 Sec 内存限制: 128 MB Special Judge 提交: 197 解决: 63 [提交] [状态] [命题人:admin] 题目描述 众所周知&#xff0c;一战过后&#xff0c;在世界列强建造超无畏级战列舰的竞争之中&#xff0c;旧日本海军根据“个舰优越主义”&#xff0c;建造了扶…

大凤号装甲空母【找规律+矩阵快速幂】

大凤号装甲空母 时间限制: 1 Sec 内存限制: 128 MB 提交: 108 解决: 15 [提交] [状态] [命题人:admin] 题目描述 大凤号航空母舰很喜欢算术。 它&#xff0c;是旧日本海军中最为先进的航空母舰。 它&#xff0c;是旧日本海军中最为短命的航空母舰。 同时&#xff0c;她还是最平…

Degree Sequence of Graph G【模拟】

Degree Sequence of Graph G 时间限制: 1 Sec 内存限制: 128 MB 提交: 362 解决: 92 [提交] [状态] [命题人:admin] 题目描述 Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep lov…

【动态规划】魔法石矿

【动态规划】魔法石矿 时间限制: 1 Sec 内存限制: 64 MB 提交: 116 解决: 27 [提交] [状态] [命题人:admin] 题目描述 为了找到回家的路&#xff0c;张琪曼施展魔法&#xff0c;从高维空间召唤出了一种叫作“读者”的生物&#xff0c;据说“读者”这种生物无所不能&#xff0c;…

简单类及成员实例【C#】

简单类及成员实例&#xff08;C#&#xff09; 题目描述 简单类及成员实例。定义了如下图所示类Student&#xff0c;根据下图和给出代码&#xff0c;补写缺失的代码。 using System; namespace sample{ class Student { public string studentid;//学号 p…

c#随机数的产生与输出【C#】

c#随机数的产生与输出 题目描述 编写一个实例方法Method01。该方法使用Random类随机产生n个3位数字&#xff08;如636&#xff09;的随机正整数&#xff0c;并把产生的随机数存入数组中并输出该数组int num Convert.ToInt32(Console.ReadLine()); using System; using System…

C# teacher类【C#】

C# teacher类 题目描述 定义一个教师类Teacher&#xff0c;具体要求如下&#xff1a; 1、私有字段工号no&#xff08;string&#xff09;、姓名name&#xff08;string&#xff09;、出生日期birthday&#xff08;DateTime&#xff09;、性别sex&#xff08;SexFlag&#xff0…

接口实例(C#,IShape)【C#】

接口实例&#xff08;C#,IShape&#xff09; 题目描述 接口实例。接口和类如下图所示&#xff0c;根据给出代码&#xff0c;补写缺失的代码&#xff0c;然后在Program类的静态Main方法中验证所实现的类。 using System; namespace Myinterface { public interface IShape…

1439: 2.4.5 Fractions to Decimals 分数化小数

1439: 2.4.5 Fractions to Decimals 分数化小数 时间限制: 1 Sec 内存限制: 64 MB提交: 194 解决: 13题目描述 写一个程序&#xff0c;输入一个形如N/D的分数(N是分子&#xff0c;D是分母)&#xff0c;输出它的小数形式。 如果小数有循环节的话&#xff0c;把循环节放在一对圆…

Problem B: 求各位数字之和

#include <stdio.h> #include <stdlib.h> int main() { int n,sum0,m; while(~scanf("%d",&n)) { while(n>0) { mn%10; nn/10; summ; } printf("%d\n",sum); sum0; } return 0; }

Problem C: 判断字符串是否为回文

#include <stdio.h> #include <stdlib.h> int main() { int i,j,n; char str[10]; gets(str); nstrlen(str); for(i0,jn-1;i<j;i,j--) { if(str[i]!str[j]) { printf("No\n"); break; } } if(i>j)printf("Yes\n"); return 0; }

Problem A: 童年生活二三事

斐波那契数列:F(n)F(n-1)F(n-2) #include <stdio.h> #include <stdlib.h> int f(int n) {int b;if(n1)b1;if(n2)b2;if(n>2)bf(n-1)f(n-2);return b; }int main() {int a,n;while(~scanf("%d",&n)&&n!0){af(n);printf("%d\n",a…

Problem C: 01字串

#include <stdio.h> #include <stdlib.h>int main() {int i,j,n0,m0;char a[129][8];for(i0;i<128;i){for(j0;j<7;j){a[i][j]n%2;nn/2;}m;nm;}for(i0;i<128;i){for(j6;j>0;j--)printf("%d",a[i][j]);printf("\n");}return 0; }

汉诺塔III

#include <stdio.h> #include <stdlib.h> int main() {int fx(int );int n,m;while(~scanf("%d",&n)){mfx(n);printf("%d\n",m);}return 0; } int fx(int n) {int m;if(n1)m2;if(n>1)m3*fx(n-1)2;return m; }

骨牌铺方格

骨牌铺方格 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 46495 Accepted Submission(s): 22470 Problem Description在2n的一个长方形方格中,用一个1 2的骨牌铺满方格,输入n ,输出铺放方案的总数.例如n3时…

递归思想完成n皇后问题

已经很长时间不敲代码了&#xff0c;感觉自己越来与颓废&#xff0c;所以现在又想做回一名苦逼的程序员&#xff0c;开启自己的代码之路。 我是根据视频敲的&#xff0c;没有题目&#xff0c;先看个四皇后问题吧。 所谓4皇后问题就是求解如何在44的棋盘上无冲突的摆放4个皇后棋…

virtualbox的USB识别

VirtualBox识别USB教程 作者&#xff1a;Vincent June 13, 2017 在Virtualbox虚拟机配置面板中打开USB设备选项&#xff0c;分别勾选上“启动USB控制器”“启用usb2.0控制器”选项&#xff0c;如果有错误去https://www.virtualbox.org/wiki/Downloads 下载相应版本的插件包&a…