All Tracks Algorithms Searching Binary Search Problem

Monk and circular distance
Tag(s):

Algorithms, Easy-Medium

Problem
Editorial
Analytics

Its time for yet another challenge, and this time it has been prepared by none other than Monk himself for Super-Hardworking Programmers like you. So, this is how it goes:

Given $$N$$ points located on the co-ordinate plane, where the $$i^{th}$$ point is located at co-ordinate $$(x_{i}$$, $$y_{i})$$, you need to answer $$q$$ queries.

In the $$i^{th}$$ query, you shall be given an integer $$r_{i}$$, and considering you draw a circle centered at the origin $$(0,0)$$ with radius $$r_{i}$$, you need to report the number of points lying inside or on the circumference of this circle.

For each query, you need to print the answer on a new line.

Input Format :

The first line contains a single integer $$N$$ denoting the number of points lying on the co-ordinate plane. Each of the next $$N$$ lines contains $$2$$ space separated integers $$x_{i}$$ and $$y_{i}$$, denoting the $$x$$ and $$y$$ co-ordintaes of the $$i^{th}$$ point.

The next line contains a single integer $$q$$, denoting the number of queries. Each of the next $$q$$ lines contains a single integer, where the integer on the $$i^{th}$$ line denotes the parameters of the $$i^{th}$$ query $$r_{i}$$.

Output Format :

For each query, print the answer on a new line.

Constraints :

$$ 1 \le N \le 10^5 $$

$$ -10^9 \le x_{i} , y_{i} \le 10^9 $$

$$ 1 \le q \le 10^5 $$

$$ 0 \le r_{i} \le 10^{18} $$

SAMPLE INPUT
5
1 1
2 2
3 3
-1 -1
4 4
2
3
32
SAMPLE OUTPUT
3
5
Explanation

For the $$1^{st}$$ query in the sample, the circle with radius equal to $$3$$ looks like this on the co-ordinate plane

enter image description here

The points : $$(1,1)$$, $$(-1,-1)$$ and $$(2,2)$$ lie inside or on the circumference of the circle.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

CodeMonk (Searching)

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications