#P10222. [省选联考 2024] 最长待机

[省选联考 2024] 最长待机

Problem Description

Elf programmers ω\omega and \aleph have infinite lifespans, so besides writing code, they often play some competitive games to kill time. Even so, they still have too much time, so they invented a game specifically for killing time: Longest Standby.

To understand the rules of Longest Standby, you first need to know the rules of the programming language Sleep++ used by the elves:

  • A program consists of nn functions. The ii-th function (1in)(1 \le i\le n) has a type eie_i and a subfunction index sequence Qi=(Qi,1,Qi,2,,Qi,li)Q_i = (Q_{i,1},Q_{i,2},\cdots,Q_{i,l_i}). QiQ_i can be empty, in which case lil_i is 00.

  • nn and all eie_i and QiQ_i can be chosen arbitrarily by the programmer, but they must satisfy all of the following conditions:

    • n1n\ge 1;
    • 1in\forall 1 \le i \le n, ei{0,1}e_i \in \{0, 1\};
    • 1in\forall 1 \le i \le n, the elements in QiQ_i are pairwise distinct and are all integers in [i+1,n][i + 1, n];
    • 2jn\forall 2 \le j \le n, exactly one Qi(1in)Q_i(1 \le i \le n) contains jj.
  • When calling function i(1in)i(1 \le i \le n), the following operations are executed in order:

    • If ei=0e_i = 0, set variable rir_i to 11; otherwise, the programmer must immediately input a positive integer value for rir_i.
    • If QiQ_i is empty, the program waits for rir_i seconds; otherwise, repeat the following operations rir_i times:
      • Call the functions numbered Qi,1,Qi,2,,Qi,liQ_{i,1},Q_{i,2},\cdots,Q_{i,l_i} in order.
  • If a type 11 function jj is called multiple times, then each call requires inputting rjr_j.

  • We consider that in a function call, all operations other than “wait for rr seconds” take no time, i.e. function calls, execution, and input are completed instantly. Therefore, within a single moment, a programmer may input multiple numbers.

It can be proven that calling any function of any Sleep++ program, no matter how the inputs are set, always takes a finite amount of time.

The rules of the game “Longest Standby” are as follows:

  • ω\omega and \aleph each prepare their own Sleep++ program and choose one function from their own program. They both know the structure of the other’s program and the chosen function.

  • At time 00, ω\omega and \aleph simultaneously call their chosen functions, and the game begins.

  • At time tt (t0t \ge 0), both sides can see all numbers the other side input at times 00 to (t1)(t - 1), and adjust the numbers they input at time tt accordingly, but neither side can know the number the other side inputs at time tt.

  • The side whose function call ends first loses the game, and the other side wins. If both calls end at the same time, it is a draw.

Both ω\omega and \aleph are extremely smart. In their view, if either side has a sure-win strategy, then the game is unfair. In other words, a game is fair if neither side has a sure-win strategy.

ω\omega wrote a Sleep++ program with nn functions and performed mm operations. There are two kinds of operations:

  • Operation 1: given kk, change eke_k to (1ek)(1 - e_k);
  • Operation 2: given kk, play one round of “Longest Standby” with \aleph. At the start, ω\omega will call their own function kk.

\aleph believes in minimalism. For each game, it wants to design a program with as few functions as possible, such that choosing some function in it 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 in it such that the game is fair.

Input Format

The first line contains two positive integers n,mn,m, representing the number of functions in ω\omega’s program and the number of operations.

The next nn lines describe function ii in ω\omega’s program. Line ii contains several integers:

  • The first two integers ei,lie_i, l_i denote the function type and the length of the subfunction index sequence;
  • The next lil_i integers Qi,1,Qi,2,,Qi,liQ_{i,1},Q_{i,2},\cdots,Q_{i,l_i} describe the subfunction index sequence.

The next mm lines each contain two integers oj,kjo_j, k_j, describing one operation, where oj=1o_j = 1 denotes operation 1 and oj=2o_j = 2 denotes operation 2.

Output Format

For each operation 2, output one line with one integer, representing the minimum number of functions required in \aleph’s program.

3 6
0 2 2 3
0 0
0 0
2 1
1 3
2 1
1 3
1 2
2 1
3
3
1

Hint

[Sample 1 Explanation]

  • For the first two games, \aleph can provide a program that is exactly the same as ω\omega’s and call function 11 when the game starts. It can be proven that there is no solution with fewer functions.

  • For the third game, \aleph can provide a program that contains only one type 11 function, and call function 11 when the game starts.

    • At time 00, ω\omega inputs r2r_2 in their program, and \aleph inputs r1r_1 in their program.
      • Note: the rr 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 (r2+1)(r_2 +1), and \aleph’s program ends at time r1r_1.
    • Since at time 00 neither side knows the other’s decision, they cannot guarantee the relationship between (r2+1)(r_2 + 1) and r1r_1, so neither side has a sure-win strategy, and the game is fair.

[Sample 2]

See sleep2.in/ans in the attachment.

This testdata satisfies special property AD.

[Sample 3]

See sleep3.in/ans in the attachment.

This testdata satisfies special property BD.

[Sample 4]

See sleep4.in/ans in the attachment.

This testdata satisfies special property D.

[Sample 5]

See sleep5.in/ans in the attachment.

This testdata satisfies special property C.

[Subtasks]

For all testdata,

  • 1n5×1051 \le n \le 5\times 10^5, 1m2×1051 \le m \le 2\times 10^5;
  • 1in\forall 1 \le i \le n, ei{0,1}e_i\in \{0, 1\}, 0li<n0 \le l_i <n;
  • 1in,1jli\forall 1 \le i \le n,1 \le j \le l_i, i<Qi,jni < Q_{i,j} \le n;
  • 1in,1p<qli\forall 1 \le i \le n, 1 \le p < q \le l_i, Qi,pQi,qQ_{i,p}\neq Q_{i,q};
  • 2jn\forall 2 \le j \le n, exactly one Qi(1in)Q_i(1 \le i \le n) contains jj;
  • 1jm\forall 1 \le j \le m, 1oj21 \le o_j \le 2, 1kjn1 \le k_j \le n.
Test Point ID nn \le mm\le Special Property
121\sim 2 33 2424 None
33 8080 400400 AD
44 BD
565\sim 6 D
77 3×1053\times 10^5 10510^5 AD
88 BD
9109\sim 10 D
1111 A
1212 BC
1313 B
141514\sim 15 C
161716\sim 17 None
181918\sim 19 5×1055\times 10^5 2×1052\times 10^5 A
2020 BC
2121 B
222322\sim 23 C
242524\sim 25 None

Special property A: guaranteed that

  • At any time, e1e_1 is always 00;
  • 2in\forall 2\le i \le n, li1l_i \le 1;
  • In operation 2, kk is always 11.

Special property B: guaranteed that

  • In operation 2, kk satisfies that at that time eke_k is 11.

Special property C: guaranteed that

  • 2in\forall 2\le i \le n, iQi2i \in Q_{\lfloor \frac{i}{2}\rfloor};
  • 1in\forall 1 \le i \le n, the sequence QiQ_i is strictly increasing.

Special property D: guaranteed that

  • There are at most 1010 operation 2 queries;
  • In operation 2, kk is always 11.

Translated by ChatGPT 5