#P7711. 3D Point Weight Query and Update

    ID: 20898 Type: Default 1000ms 256MiB

3D Point Weight Query and Update

3D Point Weight Query and Update

We are given n points in a three-dimensional space. Each point i has coordinates \(X_i, Y_i, Z_i\) and an associated weight \(a_i\). In addition, each point holds a value \(b_i\) which is initially \(0\). You are also given m operations. Each operation is provided in the format:

x y z w

For each operation, you must perform the following two steps in order:

  1. Compute and output the sum \[ S = \sum_{i:\; X_i \le x,\; Y_i \le y,\; Z_i \le z} b_i \] over all points satisfying \(X_i \le x,\; Y_i \le y,\; Z_i \le z\).
  2. For every point that satisfies \(X_i \le x,\; Y_i \le y,\; Z_i \le z\), update its value \(b_i\) as follows: \[ b_i \gets b_i + a_i \times w. \]

It is guaranteed that after processing each operation the points and operations remain the same except for the updated \(b_i\) values. Your task is to process all operations and output the corresponding sum computed in step 1 for each operation.

inputFormat

The first line contains two integers \(n\) and \(m\) which denote the number of points and operations respectively.

The next \(n\) lines each contain four integers \(X_i\), \(Y_i\), \(Z_i\) and \(a_i\) representing the coordinates and weight of the i-th point. Note that the initial value \(b_i\) of each point is \(0\) and is not part of the input.

The following \(m\) lines each contain four integers \(x\), \(y\), \(z\) and \(w\) corresponding to an operation.

outputFormat

For each of the \(m\) operations, output a single line containing the computed sum \(S\) before the update.

sample

3 2
1 2 3 2
2 2 2 3
3 3 3 5
2 2 3 1
3 3 3 2
0

5

</p>