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

31735번 - Escape Route 2 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB152151410.687%

문제

The IOI Kingdom consists of $N$ cities lined up from west to east, with cities numbered from 1ドル$ to $N$ in order from west.

In the IOI Kingdom, they use Byou as the unit of time. A day in the IOI Kingdom is divided into $T$ units of time. The moment $x$ Byous (0ドル ≤ x < T$) after the beginning of a day is called time $x$. Therefore, when 1ドル$ Byou passes from time $T - 1$ of a certain day, it becomes time 0ドル$ of the next day.

JOI Group is one of the secret sects in the IOI Kingdom. Since it is a secrect sect, members must navigate around the country’s checkpoints. Consequently, JOI Group members are restricted to using only flights operated by JOY Airlines for intercity travel.

JOY Airlines operate $M_i$ flights departing from city $i$ (1ドル ≤ i ≤ N - 1$). The $j$-th flight (1ドル ≤ j ≤ M_i$) departs from city $i$ at time $A_{i, j}$ every day and arrives at city $i + 1$ at time $B_{i, j}$ on the same day. Here, $A_{i, j} < B_{i, j}$ holds. These flights allow convenient transfers, and it is also possible to depart from a city immediately upon arrival or stay overnight at the company’s airports.

The JOI Group has $Q$ members, numbered from 1ドル$ to $Q$. Member $k$ (1ドル ≤ k ≤ Q$) places their operational base in city $L_k$ and their living base in city $R_k$. Therefore, they want to know the minimum time required to travel from city $L_k$ to city $R_k$ by selecting the departure time from city $L_k$ and flights to use appropriately.

Given information about the flights operated by JOY Airlines and the members of the JOI Group, create a program to find the minimum time required for each member $k$ to travel from city $L_k$ to city $R_k$.

입력

Read the following data from the standard input.

$N$ $T$

$M_1$

$A_{1,1}$ $B_{1,1}$

$A_{1,2}$ $B_{1,2}$

$\vdots$

$A_{1,M_1}$ $B_{1,M_1}$

$M_2$

$A_{2,1}$ $B_{2,1}$

$A_{2,2}$ $B_{2,2}$

$\vdots$

$A_{2,M_2}$ $B_{2,M_2}$

$\vdots$

$M_{N-1}$

$A_{N-1,1}$ $B_{N-1,1}$

$A_{N-1,2}$ $B_{N-1,2}$

$\vdots$

$A_{N-1,M_{N-1}}$ $B_{N-1,M_{N-1}}$

$Q$

$L_1$ $R_1$

$L_2$ $R_2$

$\vdots$

$L_Q$ $R_Q$

출력

Output $Q$ lines to the standard output. On the $k$-th line (1ドル ≤ k ≤ Q$), output the minimum time required for the member $k$ to travel from city $L_k$ to city $R_k$.

제한

  • 2ドル ≤ N ≤ 100,円 000$.
  • 2ドル ≤ T ≤ 10^9$.
  • $M_i ≥ 1$ (1ドル ≤ i ≤ N - 1$).
  • $M_1 + M_2 + \cdots + M_{N-1} ≤ 100,円 000$.
  • 0ドル ≤ A_{i, j} < B_{i, j} < T$ (1ドル ≤ i ≤ N - 1,ドル 1ドル ≤ j ≤ M_i$).
  • 1ドル ≤ Q ≤ 300,円 000$.
  • 1ドル ≤ L_k < R_k ≤ N$ (1ドル ≤ k ≤ Q$).
  • Given values are all integers.

서브태스크

번호배점제한
16

$N ≤ 2,円 000,ドル $M_i = 1$ (1ドル ≤ i ≤ N - 1$).

28

$N ≤ 2,円 000,ドル $M_i ≤ 5$ (1ドル ≤ i ≤ N - 1$).

317

$M_i = 1$ (1ドル ≤ i ≤ N - 1$).

423

$M_i ≤ 5$ (1ドル ≤ i ≤ N - 1$).

536

$N ≤ 90,円 000,ドル $Q ≤ 90,円 000,ドル $M_1 + M_2 + \cdots + M_{N-1} ≤ 90,円 000$.

610

No additional constraints.

예제 입력 1

4 10000
1
100 300
2
200 400
300 600
1
500 600
3
1 3
2 4
1 4

예제 출력 1

500
400
10500

As a demonstration, let us designate the day on which member $k$ departs from city $L_k$ as day 1ドル$.

Member 1ドル$ can travel from city 1ドル$ to city 3ドル$ in 500ドル$ Byou by following actions:

  1. Depart from city 1ドル$ at time 100ドル$ on day 1ドル$ and arrive at city 2ドル$ at time 300ドル$ on day 1ドル$.
  2. Depart from city 2ドル$ at time 300ドル$ on day 1ドル$ and arrive at city 3ドル$ at time 600ドル$ on day 1ドル$.

Since there is no faster way to travel, output 500ドル$ on line 1ドル$.

Member 2ドル$ can travel from city 2ドル$ to city 4ドル$ in 400ドル$ Byou by following actions:

  1. Depart from city 2ドル$ at time 200ドル$ on day 1ドル$ and arrive at city 3ドル$ at time 400ドル$ on day 1ドル$.
  2. Depart from city 3ドル$ at time 500ドル$ on day 1ドル$ and arrive at city 4ドル$ at time 600ドル$ on day 1ドル$.

Since there is no faster way to travel, output 400ドル$ on line 2ドル$.

Member 3ドル$ can travel from city 1ドル$ to city 4ドル$ in 10500ドル$ Byou by following actions:

  1. Depart from city 1ドル$ at time 100ドル$ on day 1ドル$ and arrive at city 2ドル$ at time 300ドル$ on day 1ドル$.
  2. Depart from city 2ドル$ at time 300ドル$ on day 1ドル$ and arrive at city 3ドル$ at time 600ドル$ on day 1ドル$.
  3. Depart from city 3ドル$ at time 500ドル$ on day 2ドル$ and arrive at city 4ドル$ at time 600ドル$ on day 2ドル$.

Since there is no faster way to travel, output 10500ドル$ on line 3ドル$.

This sample input satisfies the constraints of subtasks 2, 4, 5, 6.

예제 입력 2

6 10000
1
100 300
1
400 700
1
500 600
1
300 900
1
200 800
1
1 6

예제 출력 2

30700

This sample input satisfies the constraints of all subtasks.

힌트

출처

Camp > JOI Spring Training Camp > JOI 2023/2024 Spring Training Camp 4-1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

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

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