日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【二维差分】Monitor

發布時間:2025/3/8 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【二维差分】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; }

?

總結

以上是生活随笔為你收集整理的【二维差分】Monitor的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。