luogu#P5166. xtq的口令

xtq的口令

Background

In third grade, xtq already showed excellent physical fitness, so the PE teacher allowed him to skip the class exercises and move freely.

xtq is now observing his classmates running.

Problem Description

There are nn students lined up for running.

The PE teacher gave an order, asking these nn students to speed up. However, because the wind was too strong, only some students heard and carried out the order. At the same time, if a student who did not hear the order observes other students carrying out the order, he will also carry out the order.

Now we generalize this situation. We number the student at the front of the line as 11, the next as 22, and so on, with the student at the end numbered nn.

After observation, xtq provides for each student several observed targets. This means that when this student sees any one of his observed targets speed up (carry out the order), he will also speed up (carry out the order). It is guaranteed that for any student, all of his observed targets have indices smaller than his own (a student only observes some of the students in front of him).

Now there are qq queries or modifications:

Query: in the form of 1 L R.

Answer: if the students with indices in [L,R]\left[L,R \right] have heard the order, at least how many more students need to hear the order to make everyone carry out the order.

Modification: in the form of 2 L R x.

For each student in [L,R]\left[L,R \right], add student xx as one of his observed targets. It is guaranteed that x<Lx < L. If someone in the interval already has student xx as an observed target, ignore it.

Input Format

The first line contains two integers n,qn,q.

In the next nn lines, the first integer of each line is aia_i, meaning student ii is observed by a total of aia_i students. Then follow aia_i integers, which are the indices of the students who observe student ii. If ai=0a_i=0, it means no one observes this student. Since a student can only be observed by students behind him, the input indices are guaranteed to be greater than this student's own index.

Note that the input indices are the indices of students who observe student ii, not the indices of students observed by student ii.

Then follow qq lines, each being a query or a modification, in the formats described above.

Output Format

For each query operation, output the minimum number of additional students who need to know the order so that eventually every student carries out the teacher's order.

4 4
1 3
1 3
1 4
0
1 2 3
1 1 1
2 2 3 1
1 1 1
1
1
0

Hint

【Sample Explanation】

In the sample, student 11 is observed by student 33, student 22 is observed by student 33, and student 33 is observed by student 44.

For the first query 1 2 3: this means students 22 and 33 heard the teacher's order. Since student 33 is observed by student 44, after student 33 speeds up, student 44 will also speed up. Therefore, we need to tell student 11 what the order is, so that all students receive the order.

【Constraints】 |ID|n|Special Property| | ------ | ------ | ------ | |1|1010|Yes| |2|1010|No| |3|500500|Yes| |4|50005000|No| |5|50005000|No| |6|5000050000|Yes| |7|5000050000|No| |8|3×1053 \times 10^5|Yes| |9|3×1053 \times 10^5|No| |10|3×1053 \times 10^5|No|

Special Property: the number of modification operations does not exceed 100100.

For 100%100\% of the testdata, n,q3×105n,q\le 3 \times 10^5, ai107\sum a_i\le 10^7.

Because the input and output size of this problem is large, please do not use cin/cout.

Translated by ChatGPT 5