#P7722. Triple Count Query with Array Updates

    ID: 20909 Type: Default 1000ms 256MiB

Triple Count Query with Array Updates

Triple Count Query with Array Updates

You are given three arrays (a, b, c) each of length (n) where (1 \le a_i, b_i, c_i \le n).

There are (m) operations to process. Each operation is in one of the following forms:

1 k x: Update the (k)-th element of array (a) to (x), i.e., (a_k := x).

2 r: Query the number of triples ((i, j, k)) such that (1 \le i < j < k \le r) and (b_{a_i} = a_j = c_{a_k}).

All indices are 1-indexed and all values are integers. Compute the answer for each query operation.

inputFormat

The first line contains two integers (n) and (m), representing the length of the arrays and the number of operations.

The next three lines each contain (n) integers, representing the arrays (a), (b), and (c) respectively.

The following (m) lines contain an operation each, which is either in the format:
- 1 k x (update operation), or
- 2 r (query operation).

outputFormat

For each query operation (those starting with 2), output a single integer on a new line representing the count of triples that satisfy the condition (b_{a_i} = a_j = c_{a_k}) for (1 \le i < j < k \le r).

sample

3 3
1 2 3
2 1 3
1 3 2
2 3
1 2 1
2 3
1

0

</p>