E. Rooks and rectangles
Time limit:1 Sec Memory limit:256 MB
Topic Connection Http://codeforces.com/problemset/problem/524/E
Descriptionpolycarpus has a chessboard of size
n x
m, where
K Rooks is placed. Polycarpus hasn ' t yet invented the rules of the game he'll play. However, he has already allocated
Q Rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of?? The board is a well protected if all it vacant squares can be beaten by the rooks that stand on the this area. The rooks on the rest of the board does not affect the area ' s defense. The position of the rooks is a fixed and cannot be changed. We remind the the the the Rook beats the squares located on the same vertical or horizontal line with it, if there is no Other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas is protected. Inputthe first line contains four integers
N,
m,
kand
Q(1≤
N,
m≤100 000,1≤
k,
Q≤200-the sizes of the board, the number of rooks and the number of strategically important sites. We'll consider that the cells of the board is numbered by integers from1 to
NHorizontally and from1 to
mVertically. Next
klines contain pairs of integers "
x
y", describing the positions of the rooks (1≤
x≤
N,1≤
y≤
m). It is guaranteed, the all the rooks be in distinct squares. Next
QLines describe the strategically important areas as groups of four integers "
x
1 y 1 x 2 y 2 "( x 1≤ x 2≤ n , 1 ≤ y 1≤ y 2≤ m ). The corresponding rectangle area consists of cells x , y ), for which x 1≤ x ≤ x 2, y 1≤ y ≤ y 2. Strategically important areas can intersect of coincide.
OutputPrint
q lines. For each strategically important site print "YES" if it is the well defended and "NO" otherwise.
Sample INPUT4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3Sample Output YES
YES
NO Hintpicture to the Sample:for the last area of the answer is "NO", because cell(1, 2) cannot be hits by a rook.
Test instructions
To you, n a rectangle, to determine whether the n rectangle is covered by the car in the rectangle
Exercises
Maintain two data structures to indicate whether the first row of the column is covered in and before the first column J row is overwritten and then asked when the query is equivalent to the section i1 to I2 line This interval of the segment tree in the J1 to the J2 column of the minimum number of overlays is 0, if it is not covered by the description
Thought is more troublesome, but it's very fast to write.
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 500001#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;} int buf[10];inline void Write (int i) {int p = 0;if (i = = 0) p++; else while (i) {buf[p++] = i% 10;i/= 10;} for (int j = p-1; J >=0; j--) Putchar (' 0 ' + buf[j]); printf ("\ n");}*///**************************************************************************************inta[maxn],n,m,k,q;;structnode{intx, y;}; Node P[MAXN];structpp{intX1,y1,x2,y2,id;}; PP QUE[MAXN];voidUpdata (intXxintLintRintXintval) { if(l==R) {a[xx]=Val; return; } intM= (l+r) >>1; if(x <=M) updata (xx*2, L,m,x,val); ElseUpdata (xx*2+1, m+1, R,x,val); A[XX]=min (a[xx*2], a[xx*2+1]);}intQueryintXintLintRintLintR) { if(l<=l&&r<=R)returnA[x]; intM= (l+r) >>1; if(r<=M)returnQuery (x*2, L,m,l,r); Else if(l>M)returnQuery (x*2+1, m+1, R,l,r); Else returnMin (Query (x*2, l,m,l,r), query (x*2+1, m+1, R,l,r));}BOOLCMP (node X,node y) {returnx.x<y.x;}BOOLcmp1 (pp x,pp y) {returnx.x2<y.x2;}intANS[MAXN];voidsolve () {memset (a),0,sizeof(a)); intPic=0; for(intI=0; i<q;i++) { while(pic<k&&p[pic].x<=que[i].x2) {Updata (1,1, m,p[pic].y,p[pic].x); Pic++; } if(Query (1,1, M,que[i].y1,que[i].y2) >=que[i].x1) ans[que[i].id]=1; }}voidChange () {swap (n,m); for(intI=0; i<k;i++) swap (P[I].X,P[I].Y); Sort (p,p+k,cmp); for(intI=0; i<q;i++) {swap (que[i].x1,que[i].y1); Swap (QUE[I].X2,QUE[I].Y2); } sort (Que,que+q,cmp1);}intMain () {scanf ("%d%d%d%d",&n,&m,&k,&q); for(intI=0; i<k;i++) scanf ("%d%d",&p[i].x,&p[i].y); Sort (p,p+k,cmp); for(intI=0; i<q;i++) {scanf ("%d%d%d%d",&que[i].x1,&que[i].y1,&que[i].x2,&que[i].y2); Que[i].id=i; } sort (Que,que+Q,CMP1); Solve (); Change (); Solve (); for(intI=0; i<q;i++) { if(Ans[i]) puts ("YES"); Elseputs ("NO"); }}
VK Cup 2015-round 1 E. Rooks and rectangles segment tree fixed point modification, Interval min