RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00325

Kamioni

Unrated 레이팅 미적용
난이도
1s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

\(3^{rd}\) round, November \(29^{th}\), 2014
We are observing the movement of N trucks on the road. The road can be represented as a number line. The
points on the line denoting cities are integers. The cities are denoted with the number of the corresponding point
on the line.
All trucks are moving with the same speed and no single truck is standing still at any given moment.
Each truck takes 1 minute to pass the distance between two adjacent cities.
You are given the route of each truck. All of the trucks start their route at the same initial moment.
The route is given as an array of k cities: A1, A2, ..., A_{k}. The truck starts from city A1 and drives to city A2,
then turns and drives to city A3 and so on. Given the fact that the truck turns, it will hold:
A\(1 < A@@RISE_MATH_BLOCK_0@@3 < A\)4 > ... or A\(1 > A@@RISE_MATH_BLOCK_1@@3 > A\)4 < ...
The time it takes for the truck to turn is negligible.
One possible route is 2, 5, 1, 7. The truck is at city number 2 initially, 3 minutes after departure it arrives to city
number 5. It turns and continues towards the city number 1 in which it arrives 7 minutes after departure. It turns
again and drives towards city number 7 in which it arrives at moment 13.
After the truck completes his route, aliens appear and take it away in their space rocket.
For some pairs of trucks, we want to know the number of times they encountered each other on the road. In other
words, how many times they appeared to be on the same position (the position they encountered doesn’t need to
be an integer; i.e. they could’ve encountered at position 2.5).
Write a programme that will, for a given number of trucks N and their routes and for M pairs of trucks, determine
the number of encounters for each pair.
Please note: each pair of trucks we want to know the number of encounters for, it will hold:
• they won’t be at the same place in the moment when one of them (or both) are being taken away by aliens
• they won’t be at the same place in the initial moment or in the moment when one of them (or both) are
turning
The upper statement won’t hold for all pairs of trucks, but only the pairs we want to know the number of
encounters for.

제약

In the test cases worth 50% of total points, it will hold N ⩽\(10^{2}\), K_{i} ⩽\(10^{3}\), M ⩽\(10^{3}\).
\(3^{rd}\) round, November \(29^{th}\), 2014

입력 형식

The first line of input contains the integers N and M (1 ⩽N ⩽\(10^{5}\), 1 ⩽M ⩽\(10^{5}\)), the number of trucks and the
number of pairs of trucks we want to know the number of encounters for.
The i^{th} of the following N lines contains the description of the route of the i^{th} truck.
The first integer in the line, K_{i} (2 ⩽K_{i} ⩽\(3 \cdot 10^{5}\)) represents the number of cities on the truck’s route. After it K_{i}
integers follow, A_{j} (1 ⩽A_{j} ⩽\(10^{9}\)), the ordinal numbers of the cities on the truck’s route given in the order which
the truck visits them.
The sum of routes of all the trucks won’t exceed \(3 \cdot 10^{5}\).
Each of the following M lines contains two integers (a_{i}, b_{i}), the ordinal numbers of the trucks we want to know
the number of encounters for.

출력 형식

Output M lines. The i^{th} line must contain the number of encounters of the i^{th} pair of trucks from the input.

예제 1
입력
3 3
3 1 3 1
2 2 1
3 3 1 3
1 2
2 3
3 1
2 1
4 1 6 3 6
7 3 4 2 6 5 6 1
1 2
3 4
3 1 4 2
4 3 4 2 4
3 4 1 3
1 2
2 3
3 1
1 3
출력
output
output
1
0
2
3
2
1
2
2
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2014/2015 Contest 3

평가 및 의견

Kamioni

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Kamioni

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8