QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#8326. Longest Standby

الإحصائيات

The elf programmers $\omega$ and $\aleph$ have infinite lifespans, so when they are not writing code, they often play adversarial games to pass the time. Despite this, they still have too much time, so they invented a game specifically for killing time: Longest Standby.

To understand the rules of Longest Standby, one must first understand the rules of the programming language Sleep++ used by the elves: A program consists of $n$ functions. The $i$-th function ($1 \le i \le n$) has a type $e_i$ and a sequence of sub-function indices $Q_i = (Q_{i,1}, Q_{i,2}, \dots, Q_{i,l_i})$. $Q_i$ can be empty, in which case $l_i$ is $0$. $n$ and all $e_i$ and $Q_i$ can be provided arbitrarily by the programmer, but they must satisfy all the following conditions: $n \ge 1$; $\forall 1 \le i \le n, e_i \in \{0, 1\}$; $\forall 1 \le i \le n$, the elements of $Q_i$ are distinct and are all integers in $[i+1, n]$; $\forall 2 \le j \le n$, exactly one $Q_i$ ($1 \le i \le n$) contains $j$. When calling function $i$ ($1 \le i \le n$), the following operations are performed in order: If $e_i = 0$, set the variable $r_i$ to $1$; otherwise, the programmer must immediately input a positive integer value for $r_i$. If $Q_i$ is empty, the program waits for $r_i$ seconds; otherwise, repeat the following operation $r_i$ times: Call the functions with indices $Q_{i,1}, Q_{i,2}, \dots, Q_{i,l_i}$ in order. If a function $j$ of type $1$ is called multiple times, each call requires an input $r_j$. We consider that in a function call, operations other than "waiting for $r$ seconds" consume no time; that is, function calls, execution, and input occur instantaneously. Therefore, a programmer may input multiple numbers at a single moment.

It can be proven that calling any function of any Sleep++ program, regardless of how the input is set, always consumes a finite amount of time.

The rules of the "Longest Standby" game are as follows: $\omega$ and $\aleph$ prepare their respective Sleep++ programs and choose one function from their own programs. They know each other's program structure and the chosen function. At time $0$, $\omega$ and $\aleph$ simultaneously call their chosen functions, and the game begins. At time $t$ ($t \ge 0$), both parties can see all numbers input by the other party from time $0$ to $(t-1)$, and adjust the numbers they input at time $t$ accordingly, but neither party knows the number input by the other at time $t$. The party whose function call ends first loses the game, and the other party wins. If both calls end at the same time, it is a draw.

$\omega$ and $\aleph$ are both perfectly intelligent. In their eyes, if one party has a winning strategy, the game is unfair. In other words, a game where neither party has a winning strategy is fair.

$\omega$ has written a Sleep++ program with $n$ functions and performed $m$ operations. The operations are of two types: Operation 1: Given $k$, modify $e_k$ to $(1 - e_k)$. Operation 2: Given $k$, play a round of "Longest Standby" with $\aleph$, starting with $\omega$ calling their own function $k$.

$\aleph$ believes in minimalism. It hopes to design a program with the minimum number of functions for each game such that choosing one of them makes the game fair. Can you help it find the minimum number of functions required?

It can be proven that $\aleph$ can always design a program and choose one function such that the game is fair.

Input

The first line contains two positive integers $n, m$, representing the number of functions in $\omega$'s program and the number of operations. The next $n$ lines, the $i$-th line contains several integers describing function $i$ in $\omega$'s program: The first two integers $e_i, l_i$ represent the function type and the length of the sub-function index sequence. The next $l_i$ integers $Q_{i,1}, Q_{i,2}, \dots, Q_{i,l_i}$ describe the sub-function index sequence. The next $m$ lines, the $j$-th line contains two integers $o_j, k_j$ describing an operation, where $o_j = 1$ represents operation one, and $o_j = 2$ represents operation two.

Output

For each operation two, output one integer per line, representing the minimum number of functions required in $\aleph$'s program.

Examples

Input 1

3 6
2 0 2 2 3
3 0 0
4 0 0
5 2 1
6 1 3
7 2 1
8 1 3
9 1 2
10 2 1

Output 1

3
3
1

Note 1

  • For the first two games, $\aleph$ can provide a program identical to $\omega$'s and call function $1$ at the start of the game. It can be proven that no scheme with fewer functions exists.
  • For the third game, $\aleph$ can provide a program containing only one function of type $1$, and call function $1$ at the start of the game.
    • At time $0$, $\omega$ inputs the $r_2$ of its program, and $\aleph$ inputs the $r_1$ of its program.
      • Note: The $r$ variables are independent between $\omega$'s and $\aleph$'s programs and do not affect each other.
    • After the input is completed, $\omega$'s program ends at time $(r_2 + 1)$, and $\aleph$'s program ends at time $r_1$.
    • Since both parties do not know the other's decision at time $0$, the relationship between $(r_2 + 1)$ and $r_1$ cannot be guaranteed, so neither party has a winning strategy, and the game is fair.

Constraints

For all test data: $1 \le n \le 5 \times 10^5, 1 \le m \le 2 \times 10^5$; $\forall 1 \le i \le n, e_i \in \{0, 1\}, 0 \le l_i < n$; $\forall 1 \le i \le n, 1 \le j \le l_i, i < Q_{i,j} \le n$; $\forall 1 \le i \le n, 1 \le p < q \le l_i, Q_{i,p} \neq Q_{i,q}$; $\forall 2 \le j \le n$, exactly one $Q_i$ ($1 \le i \le n$) contains $j$; $\forall 1 \le j \le m, 1 \le o_j \le 2, 1 \le k_j \le n$.

Test Case ID $n \le$ $m \le$ Special Property
$1 \sim 2$ $3$ $24$ None
$3$ $80$ $400$ AD
$4$ $80$ $400$ BD
$5 \sim 6$ $80$ $400$ D
$7$ $3 \times 10^5$ $10^5$ AD
$8$ $3 \times 10^5$ $10^5$ BD
$9 \sim 10$ $3 \times 10^5$ $10^5$ D
$11$ $3 \times 10^5$ $10^5$ A
$12$ $3 \times 10^5$ $10^5$ BC
$13$ $3 \times 10^5$ $10^5$ B
$14 \sim 15$ $3 \times 10^5$ $10^5$ C
$16 \sim 17$ $3 \times 10^5$ $10^5$ None
$18 \sim 19$ $5 \times 10^5$ $2 \times 10^5$ A
$20$ $5 \times 10^5$ $2 \times 10^5$ BC
$21$ $5 \times 10^5$ $2 \times 10^5$ B
$22 \sim 23$ $5 \times 10^5$ $2 \times 10^5$ C
$24 \sim 25$ $5 \times 10^5$ $2 \times 10^5$ None

Special Property A: Guaranteed $e_1$ is always $0$ at any time; $\forall 2 \le i \le n, l_i \le 1$; * $k$ in operation two is always $1$.

Special Property B: Guaranteed * $k$ in operation two satisfies that the current $e_k$ is $1$.

Special Property C: Guaranteed $\forall 2 \le i \le n, i \in Q_{\lfloor i/2 \rfloor}$; $\forall 1 \le i \le n$, the sequence $Q_i$ is monotonically increasing.

Special Property D: Guaranteed There are no more than $10$ operations of type two; $k$ in operation two is always $1$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.