MWC '15 #4 P3: Salt

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 0.1s
Java 8 0.5s
Python 0.5s
Memory limit: 256M

Author:
Problem type

After failing his accounting, physics and engineering tests all in one day, aurpine has decided to give you a problem! The problem is as follows.

There are N grains of salt, labelled 1 to N. The nth grain is located at the coordinate (X_n, Y_n). Two grains won't occupy the same coordinate (because that's crazy!).

You are to answer Q queries. There are two types of queries.

  • 1 x y – if there is a piece of salt at (x, y) output salty, otherwise output bland.
  • 2 X x – output the number of pieces of salt with an x-coordinate of x.
  • 2 Y y – output the number of pieces of salt with a y-coordinate of y.

Input Specification

Input will initiate with two space separated integers N and Q on a single line.

N lines follow with two space separated integers, X_n and Y_n, the coordinate of the nth grain of salt.

Q lines follow, in the queries form explained above.

Note: fast input may be required.

Constraints

Subtask 1 [10%]

1 \le N, Q \le 100

1 \le X_n, Y_n \le 10^3

Subtask 2 [30%]

1 \le N,Q \le 10\,000

1 \le X_n, Y_n \le 10^3

Subtask 3 [60%]

1 \le N,Q \le 10\,000

1 \le X_n, Y_n \le 10^9

Output Specification

Q lines, one for each query.

Sample Input

5 4
1 2
3 5
4 3
4 5
4 7
1 2 1
1 1 2
2 X 4
2 Y 5

Sample Output

bland
salty
3
2

Explanation for Sample Output

There is no grain of salt at (2, 1). There is a grain of salt at (1, 2). There are 3 grains with an x-coordinate of 4. There are 2 grains with a y-coordinate of 5.


Comments

There are no comments at the moment.