| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.4 초 | 1024 MB | 1 | 1 | 1 | 100.000% |
Marincho has a new passion - he loves to paint with watercolors. Now he wants to make a color sequence of $N$ cells. For each cell $i$ $(1 \le i \le N),ドル Marincho has chosen a set of colors $A_i$ of size $K_i,ドル which he will mix, to paint the cell fulfilling his aesthetic feel. He has already done an initial painting of all cells numbered from $l$ to $r$ in the described manner and is now about to paint the remaining cells. Marincho follows a strictly defined order of painting the cells - the next cell that can be painted will be the one with number $l-1$ or $r+1$ (if they exist). Formally, if he has already painted all cells numbered from $L$ to $R,ドル then the next possible cells to paint are:
Unfortunately, after Marincho has painted the cells numbered from $l$ to $r$ according to the corresponding sets $A_l, A_{l+1}, \dots, A_r,ドル Marincho thinks that the sequence has become too monochromatic. Therefore, he decided that for every next cell, he paints, there has to be at least one new color, which hasn't been used in the painted cells until now. Help Marincho by writing a program aquarelle that finds whether it is possible to paint the remaining cells. Also, you have to find the answer for a few initial paintings - $Q$ pairs $l$ and $r$.
The first line of the standard input contains the positive integer $N$ -- the number of cells. The following $N$ lines contain $K_i$ and $c_1 \ c_2 \dots \ c_{K_i}$ which describe the number of colors of the corresponding set $A_i$ and the colors themselves (the colors are different positive integers). The next line contains the positive integer $Q$ -- the number of initial paintings. The last $Q$ lines contain pairs of positive integers $l$ and $r$ that specify which sequence has been painted initially.
The numbers in each line are separated by one space.
For each initial painting, in input order, print 1ドル,ドル if it is possible to finish the painting or 0ドル$ otherwise.
| Subtasks | Points | Required subtasks | $N$ | $K1 + \cdots + K_N$ |
|---|---|---|---|---|
| 1 | 11 | $≤ 15$ | $≤ 25$ | |
| 2 | 18 | 1 | $≤ 500$ | $≤ 1100$ |
| 3 | 24 | 1, 2 | $≤ 3000$ | $≤ 5 \times 10^5$ |
| 4 | 36 | 1, 2, 3 | $≤ 10^5$ | $≤ 5 \times 10^5$ |
| 5 | 11 | 1, 2, 3, 4 | $≤ 5 \times 10^5$ | $≤ 1.2 \times 10^6$ |
6 2 5 3 1 4 1 1 1 2 2 3 4 1 6 3 3 4 2 3 5 5
1 1 0
Let we analyze the first initial painting. Optimal sequence of paintings is described in the following table.
| Painted cells | Remaining paints | Paint |
|---|---|---|
| 3,ドル 4$ | 3,ドル 4, 5, 6$ | The cell with number 2ドル$. |
| 2,ドル 3, 4$ | 3,ドル 5, 6$ | The cell with number 5ドル$. |
| 2,ドル 3, 4, 5$ | 5,ドル 6$ | The cell with number 1ドル$. |
| 1,ドル 2, 3, 4, 5$ | 6ドル$ | The cell with number 6ドル$. |
| 1,ドル 2, 3, 4, 5, 6$ | $-$ | We have made a successful painting of all cells. |
Note that if we painted the cell with number 5ドル,ドル at first, we would not have been able to successfully paint all cells.
Let we analyze the third initial painting.
| Painted cells | Remaining paints | Paint |
|---|---|---|
| 5ドル$ | 1,ドル 2, 5, 6$ | The cell with number 4ドル$. |
| 4,ドル 5$ | 1,ドル 5, 6$ | The cell with number 3ドル$. |
| 3,ドル 4, 5$ | 5,ドル 6$ | The cell with number 6ドル$. |
| 3,ドル 4, 5, 6$ | 5ドル$ | We cannot continue the painting. |
Note that if we painted the cell with number 6ドル,ドル at first, then the next paintings would have been the same and we would still fail. Therefore, the answer here is 0ドル$.}\\