Question: give some vertices and give two operations: remove the vertices whose abscissa is a certain value or remove the vertices whose ordinate is a certain value. Ask the number of vertices removed each time because they are X points, for the Y operation, separate and sort X and Y. Then, for the operation, perform the binary search to check whether a point of the global variable is recorded... syntaxHighlighter. all ();
Question: give some vertices and give two operations: remove the vertices whose abscissa is a value or remove the vertices whose ordinate is a value, and ask the number of vertices removed each time.
Because it is divided into X and Y operations, the X and Y are separated, sorted, and then for the operation, binary search
Whether a point of the global variable record is removed
Sorting + binary + brute force Mark
Ah, I came to the water issue early in the morning.
[Cpp]
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define inf 110000000
# Define M 10005
# Define N 100005
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof ())
# Define LL long
# Define MOD 1000000007.
Using namespace std;
Struct Node {
Int val, id;
} X [N], y [N];
Int n, q;
Int flag [N];
Bool cmp (Node n1, Node n2 ){
Return n1.val }
Int BinSearch (Node * a, int n, int m ){
Int low = 0, high = n-1, mid, pos =-1;
While (low <= high ){
Mid = (low + high)/2;
If (a [mid]. val = m) {pos = mid; break ;}
If (a [mid]. val Else high = mid-1;
}
If (pos =-1) return 0;
Int I = pos-1, ans = 0;
While (I> = 0 & a [I]. val = m ){
If (flag [a [I]. id] = 0) {flag [a [I]. id] = 1; ans ++ ;}
I --;
}
While (pos If (flag [a [pos]. id] = 0) {flag [a [pos]. id] = 1; ans ++ ;}
Pos ++;
}
Return ans;
}
Int main (){
While (scanf ("% d", & n, & q )! = EOF & n + q ){
For (int I = 0; I Scanf ("% d", & x [I]. val, & y [I]. val );
X [I]. id = y [I]. id = I;
}
Sort (x, x + n, cmp );
Sort (y, y + n, cmp );
Mem (flag, 0 );
While (q --){
Int k, p;
Scanf ("% d", & k, & p );
If (k = 0)
Printf ("% d \ n", BinSearch (x, n, p ));
Else
Printf ("% d \ n", BinSearch (y, n, p ));
}
Puts ("");
}
Return 0;
}
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define inf 110000000
# Define M 10005
# Define N 100005
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof ())
# Define LL long
# Define MOD 1000000007.
Using namespace std;
Struct Node {
Int val, id;
} X [N], y [N];
Int n, q;
Int flag [N];
Bool cmp (Node n1, Node n2 ){
Return n1.val }
Int BinSearch (Node * a, int n, int m ){
Int low = 0, high = n-1, mid, pos =-1;
While (low <= high ){
Mid = (low + high)/2;
If (a [mid]. val = m) {pos = mid; break ;}
If (a [mid]. val Else high = mid-1;
}
If (pos =-1) return 0;
Int I = pos-1, ans = 0;
While (I> = 0 & a [I]. val = m ){
If (flag [a [I]. id] = 0) {flag [a [I]. id] = 1; ans ++ ;}
I --;
}
While (pos If (flag [a [pos]. id] = 0) {flag [a [pos]. id] = 1; ans ++ ;}
Pos ++;
}
Return ans;
}
Int main (){
While (scanf ("% d", & n, & q )! = EOF & n + q ){
For (int I = 0; I Scanf ("% d", & x [I]. val, & y [I]. val );
X [I]. id = y [I]. id = I;
}
Sort (x, x + n, cmp );
Sort (y, y + n, cmp );
Mem (flag, 0 );
While (q --){
Int k, p;
Scanf ("% d", & k, & p );
If (k = 0)
Printf ("% d \ n", BinSearch (x, n, p ));
Else
Printf ("% d \ n", BinSearch (y, n, p ));
}
Puts ("");
}
Return 0;
}