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

27414번 - Infinity War 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.8 초 8 MB9000.000%

문제

After the events that took place in New York, the N worlds from the Marvel Universe are at war. The world i (1 ≤ i ≤ N) is represented, in this final war, by an army consisting of Ki soldiers (possibly zero). Each soldier has a single super power represented by a positive integer (between 1 and P). The powers of all the soldiers in an army are different.

It has been observed that, in direct battle, two soldiers annihilate each other if and only if they have the same power. For example, if an army consisting of soldiers with powers {1, 3, 5} battles an army {2, 3, 6}, the following soldiers remain alive at the end of the battle: {1, 2, 5, 6}.

The N worlds are arranged sequentially. The first world has index 1 and the last world has index N.

Thanos is pretty sure that he can win the war and destroy the universe, but he also wants to have fun while doing it. He has prepared Q questions for you. For each question you are given two indexes x and y and you have to find the number of soldiers that would survive a battle between the armies with indexes x, x + 1, ..., y.

입력

The first line of the input contains two numbers N and Q.

The next N lines contain the descriptions of the armies. Line i+1 (where 1 ≤ i ≤ N) contains a number Ki (number of soldiers) followed by Ki numbers (power number of each soldier).

The next Q lines each contain two numbers x and y separated by a space.

출력

The output must contain Q lines. Each line must contain a single number, the answer to the corresponding question.

제한

  • 1 ≤ N ≤ 50,000
  • 1 ≤ P ≤ 10,000
  • 1 ≤ Q ≤ 100,000
  • K1 + K2 + ... + KN ≤ 300,000
  • 1 ≤ x ≤ y ≤ N for every question

서브태스크

번호배점제한
130

N ≤ 10,000, P ≤ 500 and Q ≤ 10,000

230

P ≤ 5,000 and Q ≤ 30,000

340

none

예제 입력 1

4 3
2 1 2
3 1 3 97
2 1 341
5 4 2 981 341 97
1 3
2 4
1 4

예제 출력 1

5
4
4

힌트

출처

Olympiad > Romanian Master of Informatics > Romanian Master of Informatics 2015 5번

채점 및 기타 정보

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

출처

대학교 대회

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

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