Logo
(追記) (追記ここまで)

32490번 - AQUARELLE 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.4 초 1024 MB111100.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:

  • If $L = 1$ and $R = N,ドル then all cells have been painted.
  • If $L = 1$ and $R < N,ドル then the next cell, which can be painted, is the one with number $R+1$.
  • If $L > 1$ and $R = N,ドル then the next cell, which can be painted, is the one with number $L-1$.
  • If $L > 1$ and $R < N,ドル then the next cell, which can be painted, is the one with number $L-1$ or $R+1$.

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.

제한

  • 1ドル \leq N \leq 5 \times 10^5$
  • 1ドル \leq K_i \leq 1.2 \times 10^6, K_1 + K_2 + \dots + K_N \leq 1.2 \times 10^6$
  • 1ドル \leq c_j \leq 10^6$
  • 1ドル \le l \le r \le N$
  • 1ドル \le Q \le 5$

서브태스크

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$

예제 입력 1

6
2 5 3
1 4
1 1
1 2
2 3 4
1 6
3
3 4
2 3
5 5

예제 출력 1

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ドル$.}\\

출처

Olympiad > International Autumn Tournament in Informatics > 2024 > Junior 1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /