CFR Cluj

Time limit: 6s Memory limit: 1024MB Input: Output:

Task

Because time means money, and students don't have either, much like CFR Cluj's trophy cabinet, this problem will not have a story:

You have to process qq queries of the following types:

  • 1 x y: Activate point (x,y)(x,y). It is guaranteed that an already active point with the same xx or yy coordinate does not exist.
  • 2 x y: Deactivate point (x,y)(x,y). It is guaranteed that point (x,y)(x,y) is active at the moment.
  • 3 x y: Draw open line segments ( segments which do not contain their endpoints) from point (x,y)(x,y), which is active at the moment, to all the other active points, and then print the maximum total number of intersections of a "plus" with these drawn segments (if more than one intersection occurs at the same point, all of them are counted separately). A "plus" centered in (x0,y0)(x_0,y_0), where x0,y0Rx_0,y_0 \in \mathbb{R}, is a shape formed from the two lines with equations x=x0x=x_0 and y=y0y=y_0.

Observation: The open line segments drawn in queries of type 33 are deleted after printing the answer (i.e. they do not persist through queries).

Input data

The first line contains an integer, the number of queries qq.

The next qq lines will each contain three integers tt, xx and yy - the parameters of the queries.

Output data

For each query of type 33, print the maximum number of intersections of a "plus" with the drawn open line segments.

Constraints and clarifications

  • 2q51052 \le q \le 5 \cdot 10^5
  • 1t31 \le t \le 3
  • 109x,y109-10^9 \le x,y \le 10^9
  • It is guaranteed that there is at least one query of type 33.
  • It is guaranteed that for queries of type 11, there does not exist any active point with the same xx or yy coordinate.
  • It is guaranteed that for queries of type 22 and 33, the point (x,y)(x,y) is active.
# Points Restrictions
1 24 q3 000q \leq 3 \ 000
2 40 Queries of type 22 do not exist, all the queries with type 11 appear before all the queries of type 33
3 36 No additional restrictions

Example 1

stdin

17
1 0 0
1 1 1
1 -1 -1
3 0 0
1 -2 3
1 3 -2
3 0 0
3 -1 -1
2 0 0
1 4 4
3 1 1
2 1 1
1 2 2
3 4 4
3 2 2
3 -2 3
3 3 -2

stdout

2
4
6
4
8
4
7
7

Explanation

Down below there is a graphic for the first example and query (3,1,1)(3,-1,-1), illustrating the 66 intersections:

The active points are: C(1,1)C(-1,-1), A(0,0)A(0,0), B(1,1)B(1,1), D(2,3)D(-2,3), E(3,2)E(3,-2).

A "plus" centered in point (0.5,0.75)(-0.5,-0.75) has 66 intersections, since:

  • Its vertical line intersects the segments CACA, CBCB and CECE.
  • Its horizontal line intersects the segments CACA, CBCB and CDCD.

Example 2

stdin

4
1 905580697 285643736
2 905580697 285643736
1 687880848 -231766091
3 687880848 -231766091

stdout

0

Example 3

stdin

13
1 0 0
1 1 1
1 -1 -1
1 -2 3
1 3 -2
1 4 4
1 2 2
3 -1 -1
3 1 1
3 4 4
3 2 2
3 -2 3
3 3 -2

stdout

10
6
12
8
11
11

Log in or sign up to be able to send submissions!