Monitor
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others)
Total Submission(s): 1385 Accepted Submission(s): 424
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个子矩形,代表已经被覆盖了。接下来又q个询问,每次询问一个子矩形是否全部被覆盖。
思路:可以对p个矩形做离线处理,二维差分求出前缀和,然后对于每个询问,求出该区域内的1的个数是否和矩形面积相等即可。
注意:对于一些问题,要考虑是否需在线,否则可以做离线处理,像这里处理p个给出的子矩形。另外,本题n m大小具体不定,但总的n*m<1e7,所以要动态开数组,不能用vector,vector得用pushBack操作一个一个存的。
#include<bits/stdc++.h> #include<iostream> #include<queue> #include<cstring> #include<math.h> #include<algorithm> #include<cstdio> #include<map> #include<stack> #include<vector> #define rep(i,e) for(int i=0;i<(e);++i) #define rep1(i,e) for(int i=1;i<=(e);++i) #define repx(i,x,e) for(int i=(x);i<=(e);++i) #define pii pair<int,int> #define X first #define Y second #define PB push_back #define MP make_pair #define mset(var,val) memset(var,val,sizeof(var)) #define IOS ios::sync_with_stdio(false);cin.tie(0) typedef long long ll; using namespace std; #ifdef LOCAL template<typename T> void dbg(T t){ cout<<t<<" "<<endl; } template<typename T, typename... Args> void dbg(T t, Args... args){ cout<<t<<" ";dbg(args...); } #else #define dbg(...) #endif // local typedef long long ll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; const int mod = 1e9+7; const int N = 1e4+10; typedef long long ll; #define K 137 const int maxn = 1e3+10; const int maxm =4e5+10; void work(){ int n,m,p,q,x1,x2,y1,y2; while(cin>>n>>m){ cin>>p; int **mp; mp=(int**)malloc(sizeof(int*)*(n+10)); for(int i=0;i<n+10;i++) mp[i]=(int*)malloc(sizeof(int)*(m+10)); for(int i=0;i<n+10;i++) for(int j=0;j<m+10;j++) mp[i][j]=0; for(int i = 0; i < p; i++){ cin>>x1>>y1>>x2>>y2; mp[x1][y1] += 1; mp[x2+1][y2+1] += 1; mp[x1][y2+1] -= 1; mp[x2+1][y1] -= 1; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ mp[i][j] += mp[i-1][j] + mp[i][j-1] - mp[i-1][j-1]; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(mp[i][j]) mp[i][j] = 1; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ mp[i][j] += mp[i-1][j] + mp[i][j-1] - mp[i-1][j-1]; } } cin>>q; for(int i = 0; i < q; i++){ cin>>x1>>y1>>x2>>y2; if(mp[x2][y2] - mp[x2][y1-1] - mp[x1-1][y2] + mp[x1-1][y1-1] != (x2-x1+1)*(y2-y1+1)) cout<<"NO"<<endl; else cout<<"YES"<<endl; } } } int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL IOS; work(); return 0; }
矩阵与二维前缀和相关探讨
博客围绕矩阵和二维前缀和展开,虽未给出具体内容,但可知核心聚焦于这两个信息技术领域概念,它们在数据处理、算法设计等方面有重要应用。

232

被折叠的 条评论
为什么被折叠?



