Conturbatio
Time Limit:1 Sec
Memory limit:256 MB
Topic Connection http://acm.hdu.edu.cn/showproblem.php?pid=5480
Description
There is many rook on a chessboard, a rook can attack the row and column it belongs, including their own place.
There is also many queries, each query gives a rectangle on the chess board, and asks whether every grid in the rectangle Would be attacked by any rook?
Input
The first line of the input was a integer t, meaning that there was t test cases.
Every test cases begin with four integers n,m,k,q.
K is the number of Rook, and Q is the number of queries.
Then K-lines follow, each contain, integers x, y describing the coordinate of Rook.
Then Q lines follow, each contain four integers x1,y1,x2,y2 describing the left-down and right-up coordinates of query.
1≤n,m,k,q≤100,000.
1≤x≤n,1≤y≤m.
1≤x1≤x2≤n,1≤y1≤y2≤m.
Output
For every query output "Yes" or "No" as mentioned above.
Sample Input
2
2 2 1 2
1 1
1 1 1 2
2 1 2 2
2 2 2 1
1 1
1 2
2 1 2 2
Sample Output
Yes
No
Yes
HINT
Test instructions
There are a lot of cars (Rook) on an n \times mnxm chess board, where the car can attack a row or column of his own, including where it belongs.
Now there are a lot of questions, every time I ask for a rectangle inside a checkerboard, does all the squares inside the rectangle get hit by a car?
Exercises
I am a line tree, as long as the statistics x1,x2 the minimum value of this area and Y1 y2 the minimum value of this area is not the same as 0.
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 150001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/*inline ll read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;}*///**************************************************************************************structdata{intl,r,mn;} TR[MAXN*4];d ata tr2[maxn*4];voidBuild2 (intKintSintt) {TR2[K].L=s;tr2[k].r=T; if(s==t) {tr2[k].mn=0;return;} intMid= (s+t) >>1; Build2 (k<<1, S,mid); Build2 (k<<1|1, mid+1, T); Tr2[k].mn=min (tr2[k<<1].mn,tr2[k<<1|1].mn);}intAsk2 (intKintSintt) { intL=tr2[k].l,r=TR2[K].R; if(S==L&&T==R)returntr2[k].mn; intMid= (l+r) >>1; if(T<=mid)returnAsk2 (k<<1, s,t); if(S>mid)returnAsk2 (k<<1|1, s,t); returnMin (Ask2 (k<<1, S,mid), Ask2 (k<<1|1, mid+1, T));}voidUpdate2 (intKintXinty) { intL=tr2[k].l,r=TR2[K].R; if(L==R) {tr2[k].mn=y;return;} intMid= (l+r) >>1; if(X<=mid) Update2 (k<<1, x, y); if(X>mid) Update2 (k<<1|1, x, y); Tr2[k].mn=min (tr2[k<<1].mn,tr2[k<<1|1].mn);}voidBuildintKintSintt) {TR[K].L=s;tr[k].r=T; if(s==t) {tr[k].mn=0;return;} intMid= (s+t) >>1; Build (k<<1, S,mid); Build (k<<1|1, mid+1, T); Tr[k].mn=min (tr[k<<1].mn,tr[k<<1|1].mn);}intAskintKintSintt) { intL=tr[k].l,r=TR[K].R; if(S==L&&T==R)returntr[k].mn; intMid= (l+r) >>1; if(T<=mid)returnAsk (k<<1, s,t); if(S>mid)returnAsk (k<<1|1, s,t); returnMin (Ask (k<<1, S,mid), Ask (k<<1|1, mid+1, T));}voidUpdateintKintXinty) { intL=tr[k].l,r=TR[K].R; if(L==R) {tr[k].mn=y;return;} intMid= (l+r) >>1; if(x<=mid) Update (k<<1, x, y); if(x>mid) Update (k<<1|1, x, y); Tr[k].mn=min (tr[k<<1].mn,tr[k<<1|1].mn);}intMain () {intT;SCANF ("%d",&t); while(t--) { intn,m,k,q; scanf ("%d%d%d%d",&n,&m,&k,&q); Build (1,1, N); Build2 (1,1, M); for(intI=1; i<=k;i++) { intx, y; scanf ("%d%d",&x,&y); Update (1X1); Update2 (1Y1); } for(intI=1; i<=q;i++) { intX1,x2,y1,y2; scanf ("%d%d%d%d",&x1,&y1,&x2,&X2); if(x1>x2) Swap (X1,X2); if(y1>y2) swap (y1,y2); intD1 = max (Ask (1, x1,x2), Ask2 (1, Y1,y2)); if(d1==1) printf ("yes\n"); Elseprintf ("no\n"); } } return 0;}
HDU 5480 conturbatio Segment Tree single point update, interval query minimum value