You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Dean of MAIT is going to visit Hostels of MAIT. As you know that he is a very busy person so he decided to visit only first "K" nearest Hostels. Hostels are situated in 2D plane. You are given the coordinates of hostels and you have to answer the Rocket distance of Kth nearest hostel from origin ( Dean's place ) .
7
+
8
+
// Input Format
9
+
// First line of input contains Q Total no. of queries and K There are two types of queries:
10
+
11
+
// first type : 1 x y For query of 1st type, you came to know about the co-ordinates ( x , y ) of newly constructed hostel. second type : 2 For query of 2nd type, you have to output the Rocket distance of Kth nearest hostel till now.
12
+
13
+
// The Dean will always stay at his place ( origin ). It is gauranted that there will be atleast k queries of type 1 before first query of type 2.
14
+
15
+
// Rocket distance between two points ( x2 , y2 ) and ( x1 , y1 ) is defined as (x2 - x1)2 + (y2 - y1)2
16
+
17
+
// Constraints
18
+
// 1 < = k < = Q < = 10^5
19
+
// -10^6 < = x , y < = 10^6
20
+
// Output Format
21
+
// For each query of type 2 output the Rocket distance of Kth nearest hostel from Origin.
22
+
23
+
// Sample Input
24
+
// 9 3
25
+
// 1 10 10
26
+
// 1 9 9
27
+
// 1 -8 -8
28
+
// 2
29
+
// 1 7 7
30
+
// 2
31
+
// 1 6 6
32
+
// 1 5 5
33
+
// 2
34
+
// Sample Output
35
+
// 200
36
+
// 162
37
+
// 98
38
+
// Explanation
39
+
// Here , No of queries = n = 9
40
+
// k = 3
41
+
42
+
// We have to print the kth distance from the hotel.
43
+
44
+
// We are calculating and storing the rocket distance here i.e. (x2-x1)^2 + (y2-y1)^2 … basically the cartesian distance but without the squareroot.
45
+
46
+
// First integer of each input defines the query type. 1 means take the coordinates input and 2 means display the kth distance so far.
47
+
48
+
// Iteration 1 :
49
+
// First we get 1 10 10
50
+
// Distance = 10^2 + 10^2 = 200
51
+
// We store it in our data structure. Lets call it A.
0 commit comments