Acdream 1127 (base station-tree array-2 constraints)

Source: Internet
Author: User

Base stationtime limit: 20000/10000 ms (Java/others) memory limit: 512000/256000 KB (Java/others) submitstatisticnext problemproblem description

 

In the mobile communication system, the establishment of a communication network is mainly completed by a base station.

Base stations can be divided into base stations and sub-base stations. The sub-base station is connected to various mobile users. The sub-base station must communicate with the outside world through the primary base station. The range covered by the base station is a circular area. The distance between the base station and the base station is smaller than the radius R to be covered by the base station. The radius R is determined by the transmit power of the base station.

A mobile communication network in a region contains two base stations and n sub-stations. Their positions can all correspond to an integer coordinate. If a sub-base station is overwritten by at least one base station, the sub-base station is activated.

Currently, communication companies are debugging equipment, which constantly change the transmission power of the base station. When the coverage radius of the two base stations is R1 and R2, you need to know how many sub-base stations are inactive.

 

 

 

Input

There are several groups of input data.

The first row contains four integers: X1, Y1, X2, and Y2 (1 <= x1, Y1, X2, Y2 <= 10 ^ 9 ), the coordinates of the two base stations are (x1, Y1) and (X2, Y2 ).

The second row is an integer N (1 <= n <= 100000), indicating that there are n sub-base stations.

In the next n rows, two integers x and y (1 <= X, Y <= 10 ^ 9) represent the coordinates of each sub-base station.

The next row contains an integer m (1 <= m <= 100000), indicating that M queries exist.

In the next m row, there are two integers (R1 and R2) (1 <= R1, R2 <= 10 ^ 9) in each row, indicating that when the coverage radius of the two base stations is R1 and R2, number of inactive sub-base stations. Output

Output the answer for each query.

Sample Input
1 10 5 252 61 93 86 74 1251 13 28 22 23 2
Sample output
53043
Hintsourcekuangbinmanagerdshawn

Represent the distance from the base station to the two main stations ^ 2 as two-dimensional coordinates

The query in this question is expressed as the radius ^ 2


This question is equivalent to "There are N points on the plane. Ask N-abscissa <r1OrY coordinate <R2 points ".

Use a tree array for maintenance. insert X from small to large and ask for the Y value to obtain the points in the lower left corner-> the points in the upper left corner.

Then, use the refresh command to calculate the number of points in the upper-right corner.



# Include <cstdio> # include <cstring> # include <cstdlib> # include <algorithm> # include <functional> # include <iostream> # include <cmath> # include <cctype> # include <ctime> using namespace STD; # define for (I, n) for (INT I = 1; I <= N; I ++) # define fork (I, k, n) for (INT I = K; I <= N; I ++) # define rep (I, n) for (INT I = 0; I <n; I ++) # define Ford (I, n) for (INT I = N; I --) # define repd (I, n) for (INT I = N; I> = 0; I --) # define forp (x) for (INT P = pre [X]; P = next [p]) # define lson (x <1) # define rson (x <1) + 1) # define MEM (a) memset (A, 0, sizeof (a); # define Memi () memset (A, 127, sizeof (a); # define Memi (a) memset (A, 128, sizeof (a); # define Inf (2139062143) # define F (100000007) # define maxn (100000 + 10) # define MAXXI (1000000000) # define maxm (100000 + 10) Long MUL (long a, long B) {return (A * B) % F;} long add (long a, long B) {return (a + B) % F ;} long long sub (long a, long B) {return (a-B + (a-B)/f * F + F) % F;} typedef long ll; int N, X1, Y1, X2, Y2, M, TOT; int lowbit (int x) {return X & (-x);} ll sqr (ll x) {return x * X;} ll dis2 (LL X1, ll Y1, ll X2, ll Y2) {return sqr (x1-x2) + sqr (y1-y2 );} struct arr_tree {int A [maxn + maxm * 6]; void reset () {MEM (a)} void Add1 (int x) {for (; x <= tot; X + = lowbit (x) A [x] ++;} int sum (int x) {int ans = 0; For (; x> 0; x-= lowbit (x) ans + = A [X]; return ans ;}} t; struct node {ll X, Y; // The distance from ^ 2 friend bool operator <(node A, Node B) {return. x <B. X ;}} A [maxn * 2]; struct comm {ll R1, R2; // radius ^ 2int I; friend bool operator <(Comm A, comm B) {return. r1 <B. r1 ;}} ask [maxm * 2]; int ans [maxm * 2]; ll y _ [maxn + maxm * 2]; int LOC (ll y) {return lower_bound (Y _ + 1, Y _ + 1 + tot, Y)-Y _;} int main () {While (scanf ("% d", & X1, & Y1, & X2, & Y2) = 4) {T. reset (); scanf ("% d", & N); For (I, n) {int X, Y; scanf ("% d", & X, & Y); A [I]. X = dis2 (X, Y, X1, Y1); A [I]. y = dis2 (X, Y, X2, Y2); y _ [I] = A [I]. y;} Sort (a + 1, A + 1 + n); scanf ("% d", & M); For (I, m) {int R1, R2; scanf ("% d", & R1, & R2); ask [I]. I = I; ask [I]. r1 = sqr (R1); ask [I]. r2 = sqr (R2); y _ [n + I] = ask [I]. r2;} Sort (ask + 1, ask + 1 + M); sort (Y _ + 1, Y _ + N + m + 1 ); TOT = unique (Y _ + 1, Y _ + N + m + 1)-(Y _ + 1); Int J = 1; for (I, m) {While (j <= N & A [J]. x <ask [I]. r1) T. add1 (loc (A [J]. y), J ++; ans [ask [I]. i] = j-1-T.sum (loc (ask [I]. r2)-1);} while (j <= N) T. add1 (loc (A [J]. y), J ++; For (I, m) ans [ask [I]. i] + = T. sum (loc (ask [I]. r2)-1); For (I, m) printf ("% d \ n", N-ans [I]);} return 0 ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.