#P8261. [CTS2022] 袜子

[CTS2022] 袜子

Problem Description

Given nn points (xi,yi,ci)(x_i, y_i, c_i), i=1,2,,ni = 1, 2, \dots, n. There are mm queries. Each query gives A,B,CA, B, C, and asks for the number of ordered pairs (i,j)(i, j) such that Axi+Byi+C<0Ax_i + By_i + C < 0, Axj+Byj+C<0Ax_j + By_j + C < 0, and ci=cjc_i = c_j.

Input Format

The first line contains two integers n mn\ m.

The next nn lines each contain three integers xi yi cix_i\ y_i\ c_i, i=1,2,,ni = 1, 2, \dots, n.

The next mm lines each contain three integers A B CA\ B\ C.

Output Format

Output mm lines, each containing one integer, representing the answer.

5 2
2 -1 1
0 -3 5
1 -3 2
1 3 5
3 2 2
1 2 4
1 -2 -9

2
9

Hint

Sample explanation:

The first query corresponds to (2,2)(3,3)(2, 2)(3, 3).

The second query corresponds to $(1, 1)(2, 2)(2, 4)(3, 3)(3, 5)(4, 2)(4, 4)(5, 3)(5, 5)$.

Constraints:

For 5%5\% of the testdata, n,m103n, m \le 10^3.

For another 10%10\% of the testdata, ci2c_i \le 2.

For another 15%15\% of the testdata, ci100c_i \le 100.

For another 15%15\% of the testdata, max(xi,yi)=106\max(|x_i|, |y_i|) = 10^6.

For another 15%15\% of the testdata, A=B=1|A| = |B| = 1.

For another 10%10\% of the testdata, n20000,  m200000n \le 20000,\; m \le 200000.

For the remaining testdata, there are no special constraints.

Each part of the testdata forms a subtask, with no dependencies.

All testdata satisfy:

1n500001 \le n \le 50000.

1m5000001 \le m \le 500000.

A2+B2>0A^2 + B^2 > 0.

109xi,yi,A,B,C109-10^9 \le x_i, y_i, A, B, C \le 10^9.

1cin1 \le c_i \le n.

All values are integers.

When iji \ne j, xixjx_i \ne x_j or yiyjy_i \ne y_j.

For all testdata except Subtask 4, the x,yx, y coordinates of the nn points are independently and uniformly randomly chosen within some preset intervals, and it is guaranteed that there are no duplicate points. For the ii-th point, cic_i and xi,yix_i, y_i are independently randomly chosen, but the distribution of cic_i has no special restrictions.

Translated by ChatGPT 5