#P8513. [Ynoi Easy Round 2021] TEST_136

[Ynoi Easy Round 2021] TEST_136

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 query operations. In each query, A,B,CA,B,C are given. You need to find 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 line contains one integer, the answer to the corresponding query.

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

Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.

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)(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, for every ii, 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, and the subtasks are independent.

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 chosen uniformly at random 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 chosen independently at random, but the distribution of cic_i has no special restrictions.

Translated by ChatGPT 5