実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
長さ N の数列 A = (A_1, A_2, \cdots , A_N) が与えられます。
その後に 1 以上 N 以下の整数 X が与えられます。
A_X の値を出力してください。
制約
- 1 \le X \le N \le 100
- 1 \le A_i \le 100
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N X
出力
A_X の値を出力せよ。
入力例 1
5 1 2 3 4 5 3
出力例 1
3
(A_1, A_2, A_3, A_4 , A_5) = (1, 2, 3, 4, 5) です。 A_3 = 3 のため 3 と出力してください。
入力例 2
10 6 6 9 6 10 5 7 2 8 2 4
出力例 2
6
入力例 3
10 4 4 4 3 4 2 1 1 2 1 10
出力例 3
1
Score : 100 points
Problem Statement
You are given a sequence A = (A_1, A_2, \cdots , A_N) of length N.
After that, an integer X between 1 and N, inclusive, is given.
Output the value of A_X.
Constraints
- 1 \le X \le N \le 100
- 1 \le A_i \le 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N X
Output
Output the value of A_X.
Sample Input 1
5 1 2 3 4 5 3
Sample Output 1
3
We have (A_1, A_2, A_3, A_4 , A_5) = (1, 2, 3, 4, 5). Since A_3 = 3, output 3.
Sample Input 2
10 6 6 9 6 10 5 7 2 8 2 4
Sample Output 2
6
Sample Input 3
10 4 4 4 3 4 2 1 1 2 1 10
Sample Output 3
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 個の数列 A_1, A_2, \ldots, A_N が与えられます。
数列 A_i の長さは L_i であり A_i = (A_{i,1}, A_{i,2}, \ldots, A_{i,L_i}) です。
その後、整数 X, Y が与えられます。 A_{X,Y} の値を出力してください。
制約
- 1 \le N \le 2 \times 10^5
- 1 \le L_i
- L_i の総和は 2 \times 10^5 以下
- 1 \le A_{i,j} \le 1000
- 1 \le X \le N
- 1 \le Y \le L_X
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
X Y
出力
A_{X,Y} の値を出力せよ。
入力例 1
3 3 10 20 30 1 7 4 5 6 7 8 3 4
出力例 1
8
(A_1, A_2, A_3) = ((10,20,30), (7), (5,6, 7,8)) です。
A_3 = (5, 6, 7, 8) であり、 A_{3,4} = 8 なので 8 を出力してください。
入力例 2
4 2 9 1 3 8 2 6 1 5 2 4 3 2 2
出力例 2
2
A_2 = (8, 2, 6) なので、A_{2,2} = 2 です。
入力例 3
1 5 100 200 300 400 500 1 5
出力例 3
500
Score : 200 points
Problem Statement
You are given N sequences A_1, A_2, \ldots, A_N.
The length of sequence A_i is L_i, and A_i = (A_{i,1}, A_{i,2}, \ldots, A_{i,L_i}).
After that, integers X and Y are given. Output the value of A_{X,Y}.
Constraints
- 1 \le N \le 2 \times 10^5
- 1 \le L_i
- The sum of L_i is at most 2 \times 10^5.
- 1 \le A_{i,j} \le 1000
- 1 \le X \le N
- 1 \le Y \le L_X
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
X Y
Output
Output the value of A_{X,Y}.
Sample Input 1
3 3 10 20 30 1 7 4 5 6 7 8 3 4
Sample Output 1
8
We have (A_1, A_2, A_3) = ((10,20,30), (7), (5,6, 7,8)).
Since A_3 = (5, 6, 7, 8) and A_{3,4} = 8, output 8.
Sample Input 2
4 2 9 1 3 8 2 6 1 5 2 4 3 2 2
Sample Output 2
2
Since A_2 = (8, 2, 6), we have A_{2,2} = 2.
Sample Input 3
1 5 100 200 300 400 500 1 5
Sample Output 3
500
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
整数 N,K と N 個の整数列 A_1,A_2,\ldots,A_N 、長さ N の整数列 C=(C_1,C_2,\ldots,C_N) が与えられます。整数列 A_i の長さは L_i であり A_i=(A_{i,1},A_{i,2},\ldots,A_{i,L_i}) です。また、\displaystyle 1\le K\le \sum_{i=1}^N C_iL_i が保証されます。
A と C から以下の手順で整数列 B=(B_1,B_2,\ldots,B_{\sum_{i=1}^N C_iL_i}) を構成します。
- B を長さ 0 の整数列とする。
- i=1,2,\ldots,N の順に以下の操作を行う:
- B の末尾に A_i を連結させる操作を C_i 回行う。
B_K の値を求めてください。
制約
- 1\le N
- 1\le L_i
- \displaystyle \sum_{i=1}^N L_i\le 2\times 10^5
- 1\le A_{i,j} \le 10^9 (1\le j\le L_i)
- 1\le C_i\le 10^9
- \displaystyle 1\le K\le \sum_{i=1}^N C_iL_i
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
C_1 C_2 \ldots C_N
出力
答えを出力せよ。
入力例 1
3 9 3 1 3 2 1 3 2 4 3 1 3 2
出力例 1
4
B は以下のように構成されます:
- B=() とする。
- B の末尾に A_1 を連結させる操作を 1 回行う。B=(1,3,2) となる。
- B の末尾に A_2 を連結させる操作を 3 回行う。B=(1,3,2,3,3,3) となる。
- B の末尾に A_3 を連結させる操作を 2 回行う。B=(1,3,2,3,3,3,4,3,4,3) となる。
B=(1,3,2,3,3,3,4,3,4,3) に対し B_9=4 なので 4 を出力してください。
入力例 2
3 1 1 7 1 111 1 5 1 100 10000
出力例 2
7
入力例 3
3 3163812 5 1 2 3 4 5 4 9 8 7 6 2 10 11 87043 908415 9814
出力例 3
9
Score : 300 points
Problem Statement
You are given integers N and K, along with N integer sequences A_1, A_2, \ldots, A_N and a length-N integer sequence C = (C_1, C_2, \ldots, C_N). The length of integer sequence A_i is L_i, and A_i = (A_{i,1}, A_{i,2}, \ldots, A_{i,L_i}). It is guaranteed that \displaystyle 1 \le K \le \sum_{i=1}^N C_iL_i.
Construct an integer sequence B = (B_1, B_2, \ldots, B_{\sum_{i=1}^N C_iL_i}) from A and C using the following procedure.
- Let B be an integer sequence of length 0.
- For i = 1, 2, \ldots, N in this order, perform the following operation:
- Do this C_i times: append A_i to the end of B.
Find the value of B_K.
Constraints
- 1 \le N
- 1 \le L_i
- \displaystyle \sum_{i=1}^N L_i \le 2 \times 10^5
- 1 \le A_{i,j} \le 10^9 (1 \le j \le L_i)
- 1 \le C_i \le 10^9
- \displaystyle 1 \le K \le \sum_{i=1}^N C_iL_i
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K
L_1 A_{1,1} A_{1,2} \ldots A_{1,L_1}
L_2 A_{2,1} A_{2,2} \ldots A_{2,L_2}
\vdots
L_N A_{N,1} A_{N,2} \ldots A_{N,L_N}
C_1 C_2 \ldots C_N
Output
Output the answer.
Sample Input 1
3 9 3 1 3 2 1 3 2 4 3 1 3 2
Sample Output 1
4
B is constructed as follows:
- Let B = ().
- Append A_1 to the end of B once. We get B = (1, 3, 2).
- Append A_2 to the end of B three times. We get B = (1, 3, 2, 3, 3, 3).
- Append A_3 to the end of B twice. We get B = (1, 3, 2, 3, 3, 3, 4, 3, 4, 3).
For B = (1, 3, 2, 3, 3, 3, 4, 3, 4, 3), we have B_9 = 4, so output 4.
Sample Input 2
3 1 1 7 1 111 1 5 1 100 10000
Sample Output 2
7
Sample Input 3
3 3163812 5 1 2 3 4 5 4 9 8 7 6 2 10 11 87043 908415 9814
Sample Output 3
9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
長さ N の数列 A = (A_1, A_2, \ldots, A_N) と整数 K が与えられます。
あなたは次の操作を 0 回以上 K 回以下行うことができます。
- 1 \le i \le N を満たす整数 i を 1 つ選び、A_i に i を加える。
操作後の数列に対する \displaystyle \min_{1 \le i \le N} A_i としてありうる最大値を求めてください。
制約
- 1 \le N \le 2 \times 10^5
- 1 \le A_i \le 10^{18}
- 1 \le K \le 10^{18}
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 3 1 2 3
出力例 1
3
例えば i = 1 を 2 回、 i = 2 を 1 回選ぶと、数列は (3, 4, 3) になります。このとき最小値は 3 です。
最小値を 4 以上にすることはできないため、 3 と出力して下さい。
入力例 2
4 5 10 1 10 1
出力例 2
7
入力例 3
20 457 8 9 10 9 8 8 4 6 8 1 5 10 2 8 2 6 8 1 6 6
出力例 3
132
Score : 400 points
Problem Statement
You are given a sequence A = (A_1, A_2, \ldots, A_N) of length N and an integer K.
You can perform the following operation between 0 and K times, inclusive.
- Choose an integer i satisfying 1 \le i \le N, and add i to A_i.
Find the maximum possible value of \displaystyle \min_{1 \le i \le N} A_i for the sequence after the operations.
Constraints
- 1 \le N \le 2 \times 10^5
- 1 \le A_i \le 10^{18}
- 1 \le K \le 10^{18}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \ldots A_N
Output
Output the answer.
Sample Input 1
3 3 1 2 3
Sample Output 1
3
For example, by choosing i = 1 twice and i = 2 once, the sequence becomes (3, 4, 3). In this case, the minimum value is 3.
It is impossible to make the minimum value 4 or greater, so output 3.
Sample Input 2
4 5 10 1 10 1
Sample Output 2
7
Sample Input 3
20 457 8 9 10 9 8 8 4 6 8 1 5 10 2 8 2 6 8 1 6 6
Sample Output 3
132
実行時間制限: 2.5 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
N 個のマスが左右一列に並んでいます。左から i 番目 (1\le i\le N) のマスをマス i と呼びます。
M 枚の布があり、布 i (1\le i\le M) を敷くとマス L_i からマス R_i までを覆うことができます。
Q 個のクエリに答えてください。q 番目 (1\le q\le Q) のクエリでは整数 S_q,T_q が与えられるので、以下の問題に答えてください。
- M 枚の布の中からちょうど 2 枚の布を選んで敷くことで、以下の条件を満たすことができるか判定せよ。
- マス S_q からマス T_q までは 1 枚以上の布で覆われており、それ以外のマスは布で覆われていない。
制約
- 1\le N\le 2\times 10^5
- 2\le M\le 2\times 10^5
- 1\le L_i \le R_i\le N
- 1\le Q\le 2\times 10^5
- 1\le S_q \le T_q\le N
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M L_1 R_1 L_2 R_2 \vdots L_M R_M Q S_1 T_1 S_2 T_2 \vdots S_Q T_Q
出力
各クエリに対する答えを改行区切りで出力せよ。
各クエリでは、条件を満たすように 2 枚の布を選ぶことができる場合は Yes を、できない場合は No を出力せよ。
入力例 1
4 3 1 3 1 1 2 4 4 1 4 2 4 1 3 1 1
出力例 1
Yes No Yes No
1 番目のクエリでは布 1 と布 3 を選ぶことで条件を満たすことができます。
3 番目のクエリでは布 1 と布 2 を選ぶことで条件を満たすことができます。
2,4 番目のクエリではどの 2 枚の布を選んでも条件を満たすことはできません。
入力例 2
7 10 2 6 2 5 3 6 1 6 1 2 5 6 2 3 3 7 2 3 1 2 10 1 2 3 5 1 4 1 5 1 5 5 7 1 6 2 3 5 7 2 4
出力例 2
Yes No No Yes Yes No Yes Yes No No
Score : 475 points
Problem Statement
There are N cells arranged in a horizontal row. The i-th cell from the left (1 \le i \le N) is called cell i.
There are M pieces of cloth. Laying cloth i (1 \le i \le M) covers cells L_i through R_i.
Answer Q queries. For the q-th query (1 \le q \le Q), integers S_q and T_q are given, so answer the following problem.
- Determine whether it is possible to choose exactly two pieces of cloth from the M pieces and lay them so that the following condition is satisfied.
- Cells S_q through T_q are covered by at least one piece of cloth, and no other cells are covered by any cloth.
Constraints
- 1 \le N \le 2 \times 10^5
- 2 \le M \le 2 \times 10^5
- 1 \le L_i \le R_i \le N
- 1 \le Q \le 2 \times 10^5
- 1 \le S_q \le T_q \le N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M L_1 R_1 L_2 R_2 \vdots L_M R_M Q S_1 T_1 S_2 T_2 \vdots S_Q T_Q
Output
Output the answers for the queries, separated by newlines.
For each query, output Yes if it is possible to choose two pieces of cloth satisfying the condition, and No otherwise.
Sample Input 1
4 3 1 3 1 1 2 4 4 1 4 2 4 1 3 1 1
Sample Output 1
Yes No Yes No
For the first query, the condition can be satisfied by choosing cloth 1 and cloth 3.
For the third query, the condition can be satisfied by choosing cloth 1 and cloth 2.
For the second and fourth queries, no choice of two pieces of cloth can satisfy the condition.
Sample Input 2
7 10 2 6 2 5 3 6 1 6 1 2 5 6 2 3 3 7 2 3 1 2 10 1 2 3 5 1 4 1 5 1 5 5 7 1 6 2 3 5 7 2 4
Sample Output 2
Yes No No Yes Yes No Yes Yes No No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
整数 N と長さ N - 1 の整数列 D = (D_1, D_2, \ldots, D_{N-1}) が与えられます。
(1, 2, \ldots, N) の順列 P = (P_1, P_2, \ldots, P_N) であって、次の条件を満たすものの個数を 998244353 で割った余りを求めてください。
- すべての 1 \le i \le N - 1 について、 (P_i, P_{i+1}, \ldots, P_N) の中で最大の値を持つ要素を P_a 、 2 番目に大きい値を持つ要素を P_b とすると |a - b| = D_i である。
制約
- 2 \le N \le 2 \times 10^5
- 1 \le D_i \le N - i
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
D_1 D_2 \ldots D_{N-1}
出力
条件を満たす順列の個数を 998244353 で割った余りを出力せよ。
入力例 1
3 1 1
出力例 1
4
例えば (2, 3, 1) が条件を満たしていることは、以下のように確認できます。
-
(P_1, P_2, P_3) = (2, 3, 1) である。最大の値は P_2 、 2 番目に大きい値は P_1 であり |2 - 1| = 1 = D_1 である。
-
(P_2, P_3) = (3, 1) である。最大の値は P_2 、 2 番目に大きい値は P_3 であり |2 - 3| = 1 = D_2 である。
条件を満たす順列は (1, 2, 3), (1, 3, 2), (2, 3, 1), (3, 2, 1) の 4 つです。よって 4 を出力してください。
入力例 2
5 1 2 2 1
出力例 2
0
入力例 3
15 4 4 4 4 4 4 3 2 2 2 2 2 1 1
出力例 3
70270200
Score : 525 points
Problem Statement
You are given an integer N and an integer sequence D = (D_1, D_2, \ldots, D_{N-1}) of length N - 1.
Find the number, modulo 998244353, of permutations P = (P_1, P_2, \ldots, P_N) of (1, 2, \ldots, N) that satisfy the following condition.
- For each 1 \le i \le N - 1, let P_a and P_b be the elements with the largest and the second largest values, respectively, among (P_i, P_{i+1}, \ldots, P_N); then |a - b| = D_i.
Constraints
- 2 \le N \le 2 \times 10^5
- 1 \le D_i \le N - i
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
D_1 D_2 \ldots D_{N-1}
Output
Output the number, modulo 998244353, of permutations satisfying the condition.
Sample Input 1
3 1 1
Sample Output 1
4
For example, we can verify that (2, 3, 1) satisfies the condition as follows.
-
We have (P_1, P_2, P_3) = (2, 3, 1). The largest value is P_2 and the second largest value is P_1, and |2 - 1| = 1 = D_1.
-
We have (P_2, P_3) = (3, 1). The largest value is P_2 and the second largest value is P_3, and |2 - 3| = 1 = D_2.
Four permutations satisfy the condition: (1, 2, 3), (1, 3, 2), (2, 3, 1), (3, 2, 1). Thus, output 4.
Sample Input 2
5 1 2 2 1
Sample Output 2
0
Sample Input 3
15 4 4 4 4 4 4 3 2 2 2 2 2 1 1
Sample Output 3
70270200
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 625 点
問題文
数直線上に N 個のリンゴが落ちてきます。リンゴ i は時刻 T_i に座標 X_i に落ちてきます。
あなたは数直線上にいくつかのリンゴロボを置いて N 個のリンゴを全て回収したいです。リンゴロボは好きな座標に配置することができます。
リンゴロボは時刻 0 から作動し、数直線上を左右に速さ 1 以下で自由に動かすことができます。複数のリンゴロボが同じ時刻に同じ座標にいることもできます。各リンゴロボは時刻 T_i に座標 X_i にいる時、またその時に限りリンゴ i を回収することができます。
全てのリンゴを回収するために必要なリンゴロボの台数の最小値を求めてください。
制約
- 1\le N\le 3\times 10^5
- 0\le T_i\le 3\times 10^5
- 0\le X_i\le 3\times 10^5
- (T_i,X_i) \neq (T_j,X_j) (i\neq j)
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N T_1 X_1 T_2 X_2 \vdots T_N X_N
出力
答えを出力せよ。
入力例 1
4 0 2 1 0 2 1 2 3
出力例 1
2
以下のようにリンゴロボを動かすことで 2 台のリンゴロボで全てのリンゴを回収することができます:
- リンゴロボ 1 を座標 0 に、リンゴロボ 2 を座標 2 に配置する。
- 時刻 0:リンゴロボ 2 がリンゴ 1 を回収する。
- 時刻 1:リンゴロボ 1 がリンゴ 2 を回収する。時刻 2 まで両方のリンゴロボを速さ 1 で正方向に動かす。
- 時刻 2:リンゴロボ 1 がリンゴ 3 を、リンゴロボ 2 がリンゴ 4 を回収する。
2 台未満のリンゴロボで全てのリンゴを回収することはできないので、2 を出力してください。
入力例 2
5 0 1 0 2 0 3 0 4 0 5
出力例 2
5
入力例 3
8 10 4 4 2 7 10 5 3 1 9 0 6 3 8 0 9
出力例 3
2
Score : 625 points
Problem Statement
N apples fall on a number line. Apple i falls at coordinate X_i at time T_i.
You want to place some robots on the number line to collect all N apples. The robots can be placed at any coordinates.
Each robot starts operating from time 0 and can move freely along the number line at a speed of at most 1. Multiple robots may occupy the same coordinate at the same time. Each robot can collect apple i if and only if it is at coordinate X_i at time T_i.
Find the minimum number of robots needed to collect all apples.
Constraints
- 1 \le N \le 3 \times 10^5
- 0 \le T_i \le 3 \times 10^5
- 0 \le X_i \le 3 \times 10^5
- (T_i, X_i) \neq (T_j, X_j) (i \neq j)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T_1 X_1 T_2 X_2 \vdots T_N X_N
Output
Output the answer.
Sample Input 1
4 0 2 1 0 2 1 2 3
Sample Output 1
2
All apples can be collected with two robots by moving them as follows:
- Place robot 1 at coordinate 0 and robot 2 at coordinate 2.
- Time 0: Robot 2 collects apple 1.
- Time 1: Robot 1 collects apple 2. Move both robots in the positive direction at speed 1 until time 2.
- Time 2: Robot 1 collects apple 3 and robot 2 collects apple 4.
It is impossible to collect all apples with fewer than two robots, so output 2.
Sample Input 2
5 0 1 0 2 0 3 0 4 0 5
Sample Output 2
5
Sample Input 3
8 10 4 4 2 7 10 5 3 1 9 0 6 3 8 0 9
Sample Output 3
2