| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1.5 초 | 1024 MB | 16 | 3 | 2 | 22.222% |
In this problem, the mode of a sequence is the number that appears strictly more than half the times in the sequence. Please refer to this definition in the problem.
Initially, $n$ positive integer sequences of different lengths are given, numbered from 1ドル$ to $n,ドル and the sequences can be empty. These $n$ sequences are considered to exist, and the sequences corresponding to other numbers are considered to be non-existent.
There are $q$ operations, and operations are of the following types:
-1 if the mode does not exist. The data guarantees that for any 1ドル \le i \le m$ the sequence numbered $x_i$ still exists, 1ドル \le x_i \le n + q,ドル and the concatenated sequence is non-empty. There is no guarantee that $x_i$ are distinct. The concatenation done here won't affect future operations.The first line of input contains two positive integers $n$ and $q,ドル which represent the number of initial sequences and the number of operations, respectively. It is guaranteed that $n, q \le 5 \times 10^5$.
In the next $n$ lines, the $i$-th line represents the sequence numbered $i$. The first non-negative integer $l_i$ of each line represents the length of the $i$-th sequence, followed by $l_i$ non-negative integers $a_{i,j}$ representing the elements of the sequence in order. Let $C_l = \Sigma l_i$ represent the sum of the input sequence lengths, then it is guaranteed that $C_l \le 5 \times 10^5$ and $a_{i,j} \le n + q$.
Each of the next $q$ lines represent an operation in the format described above, consisting of several integers. Let $C_m = \Sigma m$ represent the sum of all sequences that need to be concatenated in operation 3, then it is guaranteed that $C_m \leq 5 \times 10^{5}$.
For each type 3 query, output an integer on a new line, the answer to the query.
For all test data, it is guaranteed that 1ドル \le n, q, C_m, C_l \le 5 \times 10^{5}$.
2 8 3 1 1 2 3 3 3 3 3 1 1 3 1 2 4 2 1 3 3 1 3 2 3 3 1 3 1 3 1 3 1 3
1 3 -1 3 -1
The first query queries the mode of sequence 1ドル$. Since the sequence contains two 1ドル$s, more than half the length of the sequence, the mode is 1ドル$. The second query queries the mode of sequence 2ドル$. Since the sequence contains only 3ドル$s, the mode is 3ドル$. The third query asks for the mode of sequence 3ドル$. At this time, sequence 3ドル$ is $(1, 1, 2, 3, 3, 3),ドル and there is no number occuring more than 3ドル$ times, so the output is -1.
4 9 1 1 1 2 1 3 1 4 3 4 1 2 3 4 1 1 2 3 2 1 2 2 3 3 3 1 2 3 1 4 4 1 4 4 1 4 4 3 4 1 2 3 4
-1 2 2 4
The first query asks for the mode obtained after concatenating sequences 1,ドル 2, 3, 4$. The result of concatenation is $(1, 2, 3, 4),ドル and there is no number with more than two occurrences, so the output is -1. The fourth query is the mode of the sequence obtained after concatenating sequences 1,ドル 2, 3, 4$. The result of the concatenation is $(1, 2, 2, 4, 4, 4, 4),ドル which has a mode of 4ドル$.