PivotOJ

Digital Circuit

시간 제한: 2000ms메모리 제한: 1024MB출처: IOI 2022BOJ 25441

문제

There is a circuit, which consists of N+MN + M gates numbered from 00 to N+M1N + M - 1. Gates 00 to N1N - 1 are threshold gates, whereas gates NN to N+M1N + M - 1 are source gates.

Each gate, except for gate 00, is an input to exactly one threshold gate. Specifically, for each ii such that 1iN+M11 \le i \le N + M - 1, gate ii is an input to gate P[i]P[i], where 0P[i]N10 \le P[i] \le N-1. Importantly, we also have P[i]<iP[i] \lt i. Moreover, we assume P[0]=1P[0] = -1. Each threshold gate has one or more inputs. Source gates do not have any inputs.

Each gate has a state which is either 00 or 11. The initial states of the source gates are given by an array AA of MM integers. That is, for each jj such that 0jM10 \le j \le M - 1, the initial state of the source gate N+jN + j is A[j]A[j].

The state of each threshold gate depends on the states of its inputs and is determined as follows. First, each threshold gate is assigned a threshold parameter. The parameter assigned to a threshold gate with cc inputs must be an integer between 11 and cc (inclusive). Then, the state of a threshold gate with parameter pp is 11, if at least pp of its inputs have state 11, and 00 otherwise.

For example, suppose there are N=3N = 3 threshold gates and M=4M = 4 source gates. The inputs to gate 00 are gates 11 and 66, the inputs to gate 11 are gates 22, 44, and 55, and the only input to gate 22 is gate 33.

This example is illustrated in the following picture.

Suppose that source gates 33 and 55 have state 11, while source gates 44 and 66 have state 00. Assume we assign parameters 11, 22 and 22 to threshold gates 22, 11 and 00 respectively. In this case, gate 22 has state 11, gate 11 has state 11 and gate 00 has state 00. This assignment of parameter values and the states is illustrated in the following picture. Gates whose state is 11 are marked in black.

The states of the source gates will undergo QQ updates. Each update is described by two integers LL and RR (NLRN+M1N \le L \le R \le N + M - 1) and toggles the states of all source gates numbered between LL and RR, inclusive. That is, for each ii such that LiRL \le i \le R, source gate ii changes its state to 11, if its state is 00, or to 00, if its state is 11. The new state of each toggled gate remains unchanged until it is possibly toggled by one of the later updates.

Your goal is to count, after each update, how many different assignments of parameters to threshold gates result in gate 00 having state 11. Two assignments are considered different if there exists at least one threshold gate that has a different value of its parameter in both assignments. As the number of ways can be large, you should compute it modulo 10000020221\,000\,002\,022.

Note that in the example above, there are 66 different assignments of parameters to threshold gates, since gates 00, 11 and 22 have 22, 33 and 11 inputs respectively. In 22 out of these 66 assignments, gate 00 has state 11.

이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.