Question:
Bob can draw a horizontal line in an original blank rectangle or an empty rectangle separated by a vertical line, and vice versa.
After the line is drawn, Bob selects two target points in the original rectangle, and the target point is not on the painting line. Alice can delete the line to make the two points in the same empty rectangle, the deleted line must be an empty rectangle on both sides, and cannot be connected to the graph. You can find at most a few empty rectangles after the line is deleted.
Question:
It can be seen that the process of constructing a graph is a process of building a binary tree. to combine the two points, you only need to know the LCA of the rectangle where the two points are located, and delete all the lines drawn in the LCA. moreover, it is 1000 space complexity. It is enough for violent LCA.
Code:
[Cpp]
# Include <stdlib. h>
# Include <string. h>
# Include <stdio. h>
# Include <ctype. h>
# Include <math. h>
# Include <time. h>
# Include <stack>
# Include <queue>
# Include <map>
# Include <set>
# Include <vector>
# Include <string>
# Include <iostream>
# Include <algorithm>
Using namespace std;
# Define ll long
# Define ls rt <1
# Define rs ls | 1
# Define lson l, mid, ls
# Define rson mid + 1, r, rs
# Define middle l + r> 1
# Define inf 0x3f3f3f
# Define eps (1e-9)
# Define MOD 1000000007.
Typedef pair <int, int> pii;
Typedef multiset <int> mset;
Typedef multiset <int >:: iterator mst_it;
// Const double pi = acos (-1.0 );
# Define M 2000 + 5
Template <class T> T _ max (T x, T y) {return x> y? X: y ;}
Template <class T> T _ min (T x, T y) {return x <y? X: y ;}
Template <class T> void _ swap (T & x, T & y) {T z = x; x = y; y = z ;}
Int ts, cas = 0;
Int n, m;
Int xl, yl, xr, yr;
Struct pot {
Int x, y;
Pot (){}
Pot (int _ x, int _ y): x (_ x), y (_ y ){}
Void read () {scanf ("% d", & x, & y );}
};
Struct CTX {
Pot a, B;
Int l, r;
Void insert (pot _ a, pot _ B) {a = _ a, B = _ B ;}
Void read () {a. read (), B. read ();}
Bool inner (CTX t ){
Return (. x <= t. a. x & t. b. x <= B. x &. y <= t. a. y & t. b. y <= B. y );
}
};
CTX val [M], c;
Int cnt [M], l [M], r [M], tot;
Void update (int rt ){
Cnt [rt] ++;
If (l [rt] =-1 ){
Val [l [rt] = ++ tot]. insert (val [rt]. a, c. B );
Val [r [rt] = ++ tot]. insert (c. a, val [rt]. B );
Return;
}
If (val [l [rt]. inner (c) update (l [rt]);
Else if (val [r [rt]. inner (c) update (r [rt]);
}
Int query (int rt ){
If (l [rt] =-1) return cnt [rt];
If (val [l [rt]. inner (c) return query (l [rt]);
If (val [r [rt]. inner (c) return query (r [rt]);
Return cnt [rt];
}
Void run (){
Int I, j;
Scanf ("% d", & n, & m );
Memset (cnt, 0, sizeof (cnt ));
Memset (l,-1, sizeof (l ));
Memset (r,-1, sizeof (r ));
Val [tot = 1]. insert (pot (xl, yl), pot (xr, yr ));
For (I = 1; I <= n; I ++ ){
C. read ();
If (c. a. x> c. B. x) _ swap (c. a. x, c. B. x );
If (c. a. y> c. B. y) _ swap (c. a. y, c. B. y );
Update (1 );
}
While (m --){
C. read ();
If (c. a. x> c. B. x) _ swap (c. a. x, c. B. x );
If (c. a. y> c. B. y) _ swap (c. a. y, c. B. y );
Printf ("% d \ n", n-query (1) + 1 );
}
}
Void preSof (){
}
Int main (){
// Freopen ("1.in"," r ", stdin );
// Freopen ("1.out"," w ", stdout );
PreSof ();
// Run ();
While (~ Scanf ("% d", & xl, & yl, & xr, & yr) run ();
// For (scanf ("% d", & ts), cas = 1; cas <= ts; cas ++) run ();
Return 0;
}