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;
}

【二维差分】Monitor相关推荐

  1. HDU - 6514 Monitor(二维差分)

    题目链接:点击查看 题目大意:给出一个n*m的矩阵,开始全部初始化为0,然后给出一系列的小矩阵的范围,小矩阵中的格子全部变为1,最后再给出一些查询,查询矩阵范围内是否所有的格子都是1,是的话输出yes ...

  2. 一维前缀和,二维前缀和,一维差分,二维差分(翻译)

    练习一道题目 输入一个长度为n的整数序列. 接下来再输入m个询问,每个询问输入一对l, r. 对于每个询问,输出原序列中从第l个数到第r个数的和. 输入格式 第一行包含两个整数n和m. 第二行包含n个 ...

  3. 2020ICPC·小米 网络选拔赛第一场(Matrix Subtraction (二维差分))

    题目传送门 Matrix Subtraction 题目大意 给你一个 n × m n×m n×m的矩阵,每次可从矩阵中选择一个大小为 a × b a×b a×b的矩阵,使得该子矩阵的值全部减一 求最后 ...

  4. 激光导弹Gundam Unicorn(二维前缀和and二维差分)

    激光炸弹和Gundam Unicorn是二维前缀和和二位差分的综合应用. 首先是一二维差分,前缀和的模板前缀和与差分 图文并茂 超级详细整理(全网最通俗易懂)_林深不见鹿 的博客-CSDN博客_前缀和 ...

  5. 差分——(2)二维差分

    前面部分我们介绍了一维差分,https://blog.csdn.net/justidle/article/details/103761632.下面我们扩展一下,来介绍二维差分. 什么是二维差分 我们有 ...

  6. [选拔赛2 NOIP2018雅礼集训 Day3 u,v,w]玩个三角形(二维差分),玩个球(状压DP+map),玩个树(树上DP)

    文章目录 T1:玩个三角形 title solution code T2:玩个球 title solution code T3:玩个树 title solution code T1:玩个三角形 tit ...

  7. LeetCode 2132. 用邮票贴满网格图(DP/二维差分)

    文章目录 1. 题目 2. 解题 1. 题目 给你一个 m x n 的二进制矩阵 grid ,每个格子要么为 0 (空)要么为 1 (被占据). 给你邮票的尺寸为 stampHeight x stam ...

  8. ~~二维差分(附模板题)

    模板 给以(x1, y1)为左上角,(x2, y2)为右下角的子矩阵中的所有元素加上c: S[x1, y1] += c, S[x2 + 1, y1] -= c, S[x1, y2 + 1] -= c, ...

  9. 二维差分算法最细致解析

    解析前提:大家比较明白了一维差分算法和前缀和算法 大家要注意一些编程思维: 首先编程基本运算就是迭代,迭代思维是不考虑边界问题,更重要的是将计算的问题一般化,抽象化,在过程中考虑变量身份.其次就是互逆 ...

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

    题干: Monitor Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 163840/163840 K (Java/Others) To ...

最新文章

  1. smobiler介绍(二)
  2. Yii框架官方指南系列43——专题:URL(创建、路由、美化及自定义)
  3. 找到 mysql 数据库中的不良索引
  4. AI:《DEEP LEARNING’S DIMINISHING RETURNS—深度学习的收益递减》翻译与解读
  5. 神舟电脑冲击创业板失败 首发未获证监会通过
  6. Dart的套接字与web套接字
  7. IPV6之VRRP典型组网配置案例
  8. 使用Docker部署前端项目实战教程,该踩的坑我都帮你踩了!
  9. 计算机课怎么管纪律,作为班主任,班级纪律应该怎么管?丨班级圆桌派
  10. php面试题 几升水,三个水桶等分8升水的问题 -《算法的乐趣》
  11. winNTsetup安装器安装系统教程
  12. Tomcat后台管理
  13. Azure Az-900认证 04——-考取AZ900所有知识点总结--获取证书!
  14. encode decode 使用指南
  15. c++ 输出正三角形图形
  16. 让老板虎躯一震的前端技术,KPI杀手
  17. 常用的Git代码托管平台
  18. [JsHtml]全面清除前端缓存
  19. <stm32学习笔记>--基本定时器TIM6TIM7
  20. 华为桌面云虚拟机白屏无法启动的修复方法

热门文章

  1. android 机顶盒 view 焦点,AndroidTV/机顶盒 ListView获取焦点与点击事件问题处理方案...
  2. 安装 Visual Studio 插件 Visual Assist - C语言零基础入门教程
  3. Python 线程优先队列 PriorityQueue - Python零基础入门教程
  4. mysql 流程控制语句,mysql PL(procedure language)流程控制语句
  5. isfull mysql_Mysql8.0及以上版本,关于only_full_group_by的问题
  6. istio springcloud_手牵手一起学Springcloud(1)微服务这么流行,你理解了嘛?
  7. excel split函数_Excel 字符串拆分
  8. java 1的阶乘之和_1-20的阶乘之和(java)
  9. vmware linux ens32,修改Centos7的网卡ens32 改为eth0
  10. 子主题function php,php – 带有依赖项的子主题