Half Plane

아직 제출이 없습니다시간 제한12초메모리 제한1024 MB

문제

This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them.

There are nn points on the plane, where the ii-th point (x_i,y_i)(x\_i,y\_i) has value d_iD\mathbf d\_i \in D. Two sets DD and OO are given, with the following properties:

  • There exists a special element ε_D\varepsilon\_D in DD.

  • There exists a special element ε_O\varepsilon\_O in OO.

  • A binary operation +:D×DD+: D \times D \to D is given with the following properties:

    • a,bD\forall \mathbf a,\mathbf b \in D, a+b=b+a\mathbf a+\mathbf b = \mathbf b+\mathbf a
    • a,b,cD\forall \mathbf a,\mathbf b,\mathbf c \in D, (a+b)+c=a+(b+c)(\mathbf a+\mathbf b)+\mathbf c = \mathbf a+(\mathbf b+\mathbf c)
    • xD\forall \mathbf x \in D, x+ε_D=ε_D+x=x\mathbf x + \varepsilon\_D = \varepsilon\_D + \mathbf x = \mathbf x
  • A binary operation :O×DD\cdot: O \times D \to D is given with the following properties:

    • a,bO,xD\forall \mathbf a,\mathbf b \in O, \mathbf x \in D, (ab)x=a(bx)(\mathbf a \cdot \mathbf b) \cdot \mathbf x = \mathbf a \cdot (\mathbf b \cdot \mathbf x)
    • aO,x,yD\forall \mathbf a \in O, \mathbf x,\mathbf y \in D, a(x+y)=ax+ay\mathbf a \cdot (\mathbf x + \mathbf y) = \mathbf a \cdot \mathbf x + \mathbf a \cdot \mathbf y
  • A binary operation :O×OO\cdot: O \times O \to O is given with the following properties:

    • a,b,cO\forall \mathbf a,\mathbf b,\mathbf c \in O, (ab)c=a(bc)(\mathbf a \cdot \mathbf b) \cdot \mathbf c = \mathbf a \cdot (\mathbf b \cdot \mathbf c)
    • xO\forall \mathbf x \in O, xε_O=ε_Ox=x\mathbf x \cdot \varepsilon\_O = \varepsilon\_O \cdot\mathbf x = \mathbf x

In this problem, we treat DD as the set of all 3×13 \times 1 matrices over F_p\mathbb F\_{p} and OO as the set of all 3×33 \times 3 matrices over F_p\mathbb F\_{p}, where p=109+7p = 10^9+7. That is, you can treat the above operations as the usual matrix addition and matrix multiplication modulo 109+710^9+7.

Now, mm queries are given in the form a b c o:

  • Let s=ε_D\mathbf s = \varepsilon\_D.
  • For all points ii with ax_i+by_i\<cax\_i+by\_i\<c, modify s\mathbf s to s+d_i\mathbf s + \mathbf d\_i, then modify d_i\mathbf d\_i to od_i\mathbf o \cdot \mathbf d\_i.
  • Return s\mathbf s as the answer of the query.

As a data structure master, you need to perform all queries and find the answer.

입력

The first line of the input contains a single integer nn (1n31051 \le n \le 3 \cdot 10^5), indicating the number of points.

Each of the following nn lines contains five integers x_i,y_i,d_i0,d_i1,d_i2x\_i, y\_i, d\_{i0}, d\_{i1}, d\_{i2}, indicating the coordinates of the ii-th point and its value \mathbf d\_i = \left\[\begin{matrix}d\_{i0}\\\d\_{i1}\\\d\_{i2}\end{matrix}\right].

The next line of the input contains a single integer mm (1m1.51041 \le m \le 1.5 \cdot 10^4), indicating the number of the queries.

Each of the following mm lines contains twelve integers a,b,c,o_00,o_01,o_02,o_10,,o_22a, b, c, {o}\_{00}, {o}\_{01}, {o}\_{02}, {o}\_{10}, \ldots, {o}\_{22}. Note that the real \mathbf o = \left\[\begin{matrix} o\_{00} & o\_{01} & o\_{02} \\\ o\_{10} & o\_{11} & o\_{12}\\\ o\_{20} & o\_{21} & o\_{22}\end{matrix}\right].

It is guaranteed that:

  • x_i106|x\_i| \le 10^6, y_i106|y\_i| \le 10^6.
  • a_i103|a\_i| \le 10^3, b_i103|b\_i| \le 10^3, b_i0b\_i \ne 0, c_i106|c\_i| \le 10^6.
  • All matrix elements are from 00 to 109+610^9 + 6 inclusive.
  • For all 1im1 \le i \le m and 1jn1 \le j \le n, a_ix_j+b_iy_jc_ia\_i x\_j + b\_i y\_j \ne c\_i.
  • For all 1im1 \le i \le m and 1jm1 \le j \le m, (a_ib_i,c_ib_i)(a_jb_j,c_jb_j)\left(\frac{a\_i}{b\_i}, \frac{c\_i}{b\_i}\right) \ne \left(\frac{a\_j}{b\_j}, \frac{c\_j}{b\_j}\right).

출력

For each query, output a single line containing three integers s_0,s_1,s_2s\_0, s\_1, s\_2, indicating \mathbf s = \left\[\begin{matrix}s\_{0}\\\s\_{1}\\\s\_{2}\end{matrix}\right].

힌트

Note that the solution does not depend on other properties of matrix addition/multiplication than those mentioned in the statements. Defining DD and OO as sets of matrices is only for testing convenience (since we can't use the graders or interaction libraries).