問題一覧 > 通常問題

No.1347 HS Railway

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 27
作問者 : 8UqsVg4r / テスター : KoD blackyuki PCTprobability
お気に入りにしたユーザー ProblemId : 5777 / 自分の提出
問題文最終更新日: 2021-01-16 11:58:27
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
灘中入試コンテストday1 (順位表) の他の問題:

Problem Statement

Sug is planning to use HS Railway to get to his exam venue.

HS Railway has $N$ stations and $5$ types of trains. A train type is represented by an integer between $1$ and $5$, inclusive, which indicates how fast trains of that type are in rank among the $5$ types.
A train of type $i$ has starting station $L_i$ and terminal station $R_i$, and for each $j \,\, (L_i \leq j < R_i)$, it takes $A_{i, j}$ units of time to travel from station $j$ to station $j+1$. While traveling from station $j$ to station $j+1$, the speed of the train is constant.

On HS Railway, $M$ trains run in $1$ day. The $k$-th train is of type $B_k$ and departs from its starting station at time $S_k$. Each train appears at its starting station $0.1$ units of time before departing from it, and disappears $0.1$ units of time after arriving at its terminal station.

For every pair of distinct trains $(i,j) \,\, (1 \leq i < j \leq M)$, find the number of real numbers $T$ such that the position of train $i$ and the position of train $j$ coincide at time $T$, and output the sum of these counts.

Input

$N$
$L_1 \,\, R_1 \,\, A_{1,L_1} \,\, A_{1,L_1+1} \,\, \ldots \,\, A_{1,R_1-1}$
$L_2 \,\, R_2 \,\, A_{2,L_2} \,\, A_{2,L_2+1} \,\, \ldots \,\, A_{2,R_2-1}$
$L_3 \,\, R_3 \,\, A_{3,L_3} \,\, A_{3,L_3+1} \,\, \ldots \,\, A_{3,R_3-1}$
$L_4 \,\, R_4 \,\, A_{4,L_4} \,\, A_{4,L_4+1} \,\, \ldots \,\, A_{4,R_4-1}$
$L_5 \,\, R_5 \,\, A_{5,L_5} \,\, A_{5,L_5+1} \,\, \ldots \,\, A_{5,R_5-1}$
$M$
$B_1\ S_1$
$B_2\ S_2$
$\vdots$
$B_M\ S_M$

  • \(2 \leq N \leq 10^5\)
  • \(1 \leq A_{i,j} \leq 10^5\) \((1 \leq i \leq 5,L_i \leq j \leq R_i - 1)\)
  • If trains of types $i , j ( i < j )$ both pass through stations $k,k+1$, then \(A_{i, k} < A_{j, k}\)
  • \(1 \leq L_i < R_i \leq N \,\, (1 \leq i \leq 5) \)
  • \(1 \leq M \leq 10^5\)
  • \(1 \leq B_k \leq 5\ (1 \leq k \leq M)\)
  • \(1 \leq S_k \leq 10^6\ (1 \leq k \leq M) \)
  • If $1 \leq i < j \leq M$, then $S_i \neq S_j$
  • If $1 \leq i < j \leq 5$, then $L_i \neq L_j$
  • If $1 \leq i < j \leq 5$, then $R_i \neq R_j$
  • All inputs are integers

Output

For every pair of distinct trains $(i,j) \,\, (1 \leq i < j \leq M)$, find the number of real numbers $T$ such that the position of train $i$ and the position of train $j$ coincide at time $T$, and output the sum of these counts.

Sample

Sample 1
Input
8
1 2 3
3 4 6
6 7 6
5 6 8
2 5 10 10 8
2
2 13
5 2
Output
1
Train $1$ and train $2$ coincide in position between station $3$ and station $4$ at $T=\frac{29}{2}$.

Sample 2
Input
20
12 15 1 2 2 
4 14 3 6 3 4 3 3 4 2 4 5 
8 12 4 5 5 3 
7 17 6 6 6 6 5 7 8 5 9 9 
6 9 10 10 10 
18
2 9
1 16
3 13
1 20
1 17
3 19
2 10
1 12
5 5
3 18
5 4
5 14
1 8
2 3
4 15
5 1
4 2
2 11
Output
27

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。