#B3695. Set Operation Manipulation

    ID: 11354 Type: Default 1000ms 256MiB

Set Operation Manipulation

Set Operation Manipulation

We are given (n) sets (s_1,s_2,\dots,s_n), where each set contains some integers in the range ([1, m]).

Then, there are (q) operations, each of which is one of the following:

1. (1\ x\ y) – For each element in (s_x), add (y) and remove any elements greater than (m).
2. (2\ x\ y) – For each element in (s_x), subtract (y) and remove any elements less than (1).
3. (3\ x\ y) – Query the number of elements in the intersection of (s_x) and (s_y).
4. (4\ x\ y) – Query the number of elements in the union of (s_x) and (s_y).
5. (5\ x\ y) – Query the number of elements in the symmetric difference of (s_x) and (s_y) (elements belonging to exactly one set).

Process the operations in the given order and output the answer for each query (i.e. for operations of types 3, 4, and 5).

inputFormat

The first line contains three integers (n), (m), and (q).

For the next (n) lines, each line starts with an integer (k_i) (the number of elements in set (s_i)), followed by (k_i) integers representing the elements in the set.

Then, (q) lines follow, each containing an operation in one of the following forms:

(1\ x\ y), (2\ x\ y), (3\ x\ y), (4\ x\ y), or (5\ x\ y).

outputFormat

For each operation of type (3), (4) or (5), output the result on a new line.

sample

2 10 5
3 1 2 3
2 2 4
3 1 2
1 1 5
4 1 2
2 2 1
5 1 2
1

5 5

</p>