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

32579번 - Ornithology 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB40252564.103%

문제

On the outskirts of the town, close to the farm, there stand two parallel power lines, separated by a narrow dirt road. The power lines were a favorite resting spot for a variety of birds.

Today, on this cool autumn morning, the lines are filled with a group of birds. On the first line there are $n$ consecutive positions for birds numbered 0,ドル 1, \dots , n - 1$. On the second power line there are also $n$ positions numbered in the same manner.

Initially, every position of the first line is occupied by some birds (possibly zero) and there are no birds on the second power line. Each bird has its desired position to fly to on the second line. No two birds on the same position on the first line share the same desired position.

At one moment, all the birds at once will decide to fly to their desired positions. Every bird flies along the straight line segment connecting its initial and desired position.

It can happen that some pairs of birds crash into each other during their flight. This can happen when their corresponding line segments cross. We shall call such unordered pair of birds dangerous pair.

For example, if a bird on position 2ドル$ wants to go to position 1ドル$ and the bird on position 1 wants to go to position 2ドル,ドル their paths cross.

The birds will not collide if their paths have the same desired position (on the second line) or if they start from the same position (on the first line). In other words a pair of birds with the same initial or desired positions is not considered a dangerous pair.

The task is very simple. Compute the number of dangerous pairs of birds.

입력

First line of input contains an integer $n$ (1ドル ≤ n ≤ 2 \cdot 10^5$) representing the number of positions on both power lines.

Each of the next $n$ lines describe the desired positions of the birds. The $i$-th line starts with an integer $p_i$ (0ドル ≤ p_i ≤ n$) representing the number of birds on position $i$.

Then, there are $p_i$ distinct numbers $q_{i,1}, \dots , q_{i,p_i}$ (0ドル ≤ q_{i,j} ≤ n-1$) representing the desired places of the $p_i$ birds.

It is guaranteed that the sum $\sum_{i=0}^{n-1}{p_i}$ does not exceed 2ドル \cdot 10^5$.

출력

Output exactly one line containing one integer – the number of dangerous pairs of birds.

제한

예제 입력 1

3
2 1 2
1 0
1 1

예제 출력 1

3

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > CTU Open Contest > CTU Open Contest 2024 O번

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

출처

대학교 대회

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

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