Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder Beginner Contest は、今回で 214 回目の開催となりました。
今までの AtCoder Beginner Contest において、出題される問題数は次のように変化しました。
- 1 回目から 125 回目までは 4 問
- 126 回目から 211 回目までは 6 問
- 212 回目から 214 回目までは 8 問
N 回目の AtCoder Beginner Contest において出題された問題数を求めてください。
制約
- 1 \leq N \leq 214
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
214
出力例 1
8
入力例 2
1
出力例 2
4
入力例 3
126
出力例 3
6
Score : 100 points
Problem Statement
This is the 214-th AtCoder Beginner Contest (ABC).
The ABCs so far have had the following number of problems.
- The 1-st through 125-th ABCs had 4 problems each.
- The 126-th through 211-th ABCs had 6 problems each.
- The 212-th through 214-th ABCs have 8 problems each.
Find the number of problems in the N-th ABC.
Constraints
- 1 \leq N \leq 214
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
214
Sample Output 1
8
Sample Input 2
1
Sample Output 2
4
Sample Input 3
126
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
1 から N の番号が付けられた N 人の人がおり、この中で一対一の勝敗のつくゲームを何度か行いました。N 人は最初にそれぞれ持ち点として 0 を持っており、各ゲームでは勝者の持ち点が 1 増え、敗者の持ち点が 1 減ります(持ち点が負になることもあります)。最終的に人 i\ (1\leq i\leq N-1) の持ち点が A_i になったとき、人 N の持ち点を求めてください。なお、ゲームの進行によらず最終的な人 N の持ち点は一意に定まることが示せます。
制約
- 2\leq N\leq 100
- -100\leq A_i\leq 100
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \ldots A_{N-1}
出力
答えを出力せよ。
入力例 1
4 1 -2 -1
出力例 1
2
最終的に人 1,2,3 の持ち点が 1,-2,-1 となるような進行として、例えば次のようなものが考えられます。
- 最初、人 1,2,3,4 の持ち点はそれぞれ 0,0,0,0 である。
- 人 1 と 2 が対戦して、人 1 が勝利する。4 人の持ち点はそれぞれ 1,-1,0,0 である。
- 人 1 と 4 が対戦して、人 4 が勝利する。4 人の持ち点はそれぞれ 0,-1,0,1 である。
- 人 1 と 2 が対戦して、人 1 が勝利する。4 人の持ち点はそれぞれ 1,-2,0,1 である。
- 人 2 と 3 が対戦して、人 2 が勝利する。4 人の持ち点はそれぞれ 1,-1,-1,1 である。
- 人 2 と 4 が対戦して、人 4 が勝利する。4 人の持ち点はそれぞれ 1,-2,-1,2 である。
この場合、人 4 の持ち点は 2 になります。ほかにも別の進行が考えられますが、どのような進行であっても人 4 の持ち点は 2 になります。
入力例 2
3 0 0
出力例 2
0
入力例 3
6 10 20 30 40 50
出力例 3
-150
Score: 100 points
Problem Statement
There are N people labeled 1 to N, who have played several one-on-one games without draws. Initially, each person started with 0 points. In each game, the winner's score increased by 1 and the loser's score decreased by 1 (scores can become negative). Determine the final score of person N if the final score of person i\ (1\leq i\leq N-1) is A_i. It can be shown that the final score of person N is uniquely determined regardless of the sequence of games.
Constraints
- 2 \leq N \leq 100
- -100 \leq A_i \leq 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-1}
Output
Print the answer.
Sample Input 1
4 1 -2 -1
Sample Output 1
2
Here is one possible sequence of games where the final scores of persons 1, 2, 3 are 1, -2, -1, respectively.
- Initially, persons 1, 2, 3, 4 have 0, 0, 0, 0 points, respectively.
- Persons 1 and 2 play, and person 1 wins. The players now have 1, -1, 0, 0 point(s).
- Persons 1 and 4 play, and person 4 wins. The players now have 0, -1, 0, 1 point(s).
- Persons 1 and 2 play, and person 1 wins. The players now have 1, -2, 0, 1 point(s).
- Persons 2 and 3 play, and person 2 wins. The players now have 1, -1, -1, 1 point(s).
- Persons 2 and 4 play, and person 4 wins. The players now have 1, -2, -1, 2 point(s).
In this case, the final score of person 4 is 2. Other possible sequences of games exist, but the score of person 4 will always be 2 regardless of the progression.
Sample Input 2
3 0 0
Sample Output 2
0
Sample Input 3
6 10 20 30 40 50
Sample Output 3
-150
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
AtCoder Land の入り口には 1 つのチケット売り場があり、来園客はこのチケット売り場の前に一列に並んで順にチケットを購入します。 チケットの購入手続きには一人当たり A 秒かかり、列の先頭の人がチケットを購入し終わると、(存在すれば)次の人がすぐさま購入手続きを開始します。
現在チケット売り場に並んでいる人はおらず、今から N 人の人が順にチケットを買いに来ます。 具体的には、i 番目の人は今から T_i 秒後にチケット売り場を訪れ、既に列が存在すればその最後尾に並び、存在しなければすぐさま購入手続きを開始します。 ここで、T_1< T_2< \dots < T_N です。
各 i\ (1\leq i\leq N) について、i 番目の人がチケットを購入し終わるのは今から何秒後か求めてください。
制約
- 1\leq N \leq 100
- 0\leq T_1< T_2< \dots < T_N\leq 10^6
- 1\leq A\leq 10^6
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A T_1 T_2 \dots T_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、i 番目の人がチケットを購入し終わるのは今から何秒後かを整数として出力せよ。
入力例 1
3 4 0 2 10
出力例 1
4 8 14
時系列順に以下のように物事が進行します。
- 0 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 2 秒後:2 番目の人がチケット売り場を訪れ、1 番目の人の後ろに並ぶ。
- 4 秒後:1 番目の人がチケットを購入し終え、2 番目の人が購入手続きを開始する。
- 8 秒後:2 番目の人がチケットを購入し終える。
- 10 秒後:3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 14 秒後:3 番目の人がチケットを購入し終える。
入力例 2
3 3 1 4 7
出力例 2
4 7 10
時系列順に以下のように物事が進行します。
- 1 秒後:1 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 4 秒後:1 番目の人がチケットを購入し終えると同時に、2 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 7 秒後:2 番目の人がチケットを購入し終えると同時に、3 番目の人がチケット売り場を訪れ、チケットの購入手続きを開始する。
- 10 秒後:3 番目の人がチケットを購入し終える。
入力例 3
10 50000 120190 165111 196897 456895 540000 552614 561627 743796 757613 991216
出力例 3
170190 220190 270190 506895 590000 640000 690000 793796 843796 1041216
Score : 200 points
Problem Statement
At the entrance of AtCoder Land, there is a single ticket booth where visitors line up to purchase tickets one by one. The purchasing process takes A seconds per person. Once the person at the front of the line finishes purchasing their ticket, the next person (if any) immediately starts their purchasing process.
Currently, there is no one in line at the ticket booth, and N people will come to buy tickets one after another. Specifically, the i-th person will arrive at the ticket booth T_i seconds from now. If there is already a line, they will join the end of it; if not, they will start the purchasing process immediately. Here, T_1 < T_2 < \dots < T_N.
For each i\ (1 \leq i \leq N), determine how many seconds from now the i-th person will finish purchasing their ticket.
Constraints
- 1 \leq N \leq 100
- 0 \leq T_1 < T_2 < \dots < T_N \leq 10^6
- 1 \leq A \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A T_1 T_2 \dots T_N
Output
Print N lines. The i-th line should contain the number of seconds from now that the i-th person will finish purchasing their ticket.
Sample Input 1
3 4 0 2 10
Sample Output 1
4 8 14
The events proceed in the following order:
- At 0 seconds: The 1st person arrives at the ticket booth and starts the purchasing process.
- At 2 seconds: The 2nd person arrives at the ticket booth and joins the line behind the 1st person.
- At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person starts the purchasing process.
- At 8 seconds: The 2nd person finishes purchasing their ticket.
- At 10 seconds: The 3rd person arrives at the ticket booth and starts the purchasing process.
- At 14 seconds: The 3rd person finishes purchasing their ticket.
Sample Input 2
3 3 1 4 7
Sample Output 2
4 7 10
The events proceed in the following order:
- At 1 second: The 1st person arrives at the ticket booth and starts the purchasing process.
- At 4 seconds: The 1st person finishes purchasing their ticket, and the 2nd person arrives at the ticket booth and starts the purchasing process.
- At 7 seconds: The 2nd person finishes purchasing their ticket, and the 3rd person arrives at the ticket booth and starts the purchasing process.
- At 10 seconds: The 3rd person finishes purchasing their ticket.
Sample Input 3
10 50000 120190 165111 196897 456895 540000 552614 561627 743796 757613 991216
Sample Output 3
170190 220190 270190 506895 590000 640000 690000 793796 843796 1041216
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 個のマスが左右一列に並んでおり、左から順にマス 1、マス 2、…、マス N と番号づけられています。
また、K 個のコマがあり、最初左から i 番目のコマはマス A_i に置かれています。
これらに対して、Q 回の操作を行います。
i 回目の操作では次の操作を行います。
- 左から L_i 番目のコマが一番右のマスにあるならば何も行わない。
- そうでない時、左から L_i 番目のコマがあるマスの 1 つ右のマスにコマが無いならば、左から L_i 番目のコマを 1 つ右のマスに移動させる。 1 つ右のマスにコマがあるならば、何も行わない。
Q 回の操作が終了した後の状態について、i=1,2,\ldots,K に対して左から i 番目のコマがあるマスの番号を出力してください。
制約
- 1\leq K\leq N\leq 200
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1\leq Q\leq 1000
- 1\leq L_i\leq K
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K Q A_1 A_2 \ldots A_K L_1 L_2 \ldots L_Q
出力
K 個の整数を空白区切りで一行に出力せよ。 ここで、i 個目の整数は、 Q 回の操作が終了した後の状態について、左から i 番目のコマの番号を表す。
入力例 1
5 3 5 1 3 4 3 3 1 1 2
出力例 1
2 4 5
最初、コマはマス 1, 3, 4 にあります。これに対して以下のように操作が行われます。
- 左から 3 番目のコマはマス 4 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 3 番目のコマをマス 5 に動かします。 コマはマス 1, 3, 5 にある状態になります。
- 左から 3 番目のコマはマス 5 にあります。 これは一番右のマスなので、何も行いません。 コマはマス 1, 3, 5 にある状態のままです。
- 左から 1 番目のコマはマス 1 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 1 番目のコマをマス 2 に動かします。 コマはマス 2, 3, 5 にある状態になります。
- 左から 1 番目のコマはマス 2 にあります。 これは一番右のマスでありませんが、その 1 つ右のマス(マス 3 )にコマが置かれているため、何も行いません。 コマはマス 2, 3, 5 にある状態のままです。
- 左から 2 番目のコマはマス 3 にあります。 これは一番右のマスでなく、その右のマスにもコマが置かれていないため、左から 2 番目のコマをマス 4 に動かします。 コマはマス 2, 4, 5 にある状態になります。
よって、Q 回の操作が終わった後でコマはマス 2, 4, 5 に置かれているため、2,4,5 を空白区切りでこの順に出力します。
入力例 2
2 2 2 1 2 1 2
出力例 2
1 2
入力例 3
10 6 9 1 3 5 7 8 9 1 2 3 4 5 6 5 6 2
出力例 3
2 5 6 7 9 10
Score : 200 points
Problem Statement
There are N squares, indexed Square 1, Square 2, …, Square N, arranged in a row from left to right.
Also, there are K pieces. The i-th piece from the left is initially placed on Square A_i.
Now, we will perform Q operations against them.
The i-th operation is as follows:
- If the L_i-th piece from the left is on its rightmost square, do nothing.
- Otherwise, move the L_i-th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.
Print the index of the square on which the i-th piece from the left is after the Q operations have ended, for each i=1,2,\ldots,K.
Constraints
- 1\leq K\leq N\leq 200
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1\leq Q\leq 1000
- 1\leq L_i\leq K
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q A_1 A_2 \ldots A_K L_1 L_2 \ldots L_Q
Output
Print K integers in one line, with spaces in between. The i-th of them should be the index of the square on which the i-th piece from the left is after the Q operations have ended.
Sample Input 1
5 3 5 1 3 4 3 3 1 1 2
Sample Output 1
2 4 5
At first, the pieces are on Squares 1, 3, and 4. The operations are performed against them as follows:
- The 3-rd piece from the left is on Square 4. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 3-rd piece from the left to Square 5. Now, the pieces are on Squares 1, 3, and 5.
- The 3-rd piece from the left is on Square 5. This is the rightmost square, so do nothing. The pieces are still on Squares 1, 3, and 5.
- The 1-st piece from the left is on Square 1. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 1-st piece from the left to Square 2. Now, the pieces are on Squares 2, 3, and 5.
- The 1-st piece from the left is on Square 2. This is not the rightmost square, but the next square on the right (Square 3) contains a piece, so do nothing. The pieces are still on Squares 2, 3, and 5.
- The 2-nd piece from the left is on Square 3. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 2-nd piece from the left to Square 4; Now, the pieces are still on Squares 2, 4, and 5.
Thus, after the Q operations have ended, the pieces are on Squares 2, 4, and 5, so 2, 4, and 5 should be printed in this order, with spaces in between.
Sample Input 2
2 2 2 1 2 1 2
Sample Output 2
1 2
Sample Input 3
10 6 9 1 3 5 7 8 9 1 2 3 4 5 6 5 6 2
Sample Output 3
2 5 6 7 9 10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
AtCoder 王国では、これから N 日間のお祭りが開催されます。そのうち、A_1 日目、A_2 日目、\dots、A_M 日目の M 日では花火が上がります。ここで、お祭りの最終日には花火が上がることが保証されます。(つまり、A_M=N が保証されます。)
i=1,2,\dots,N に対して、以下の問題を解いてください。
- i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後か?ただし、i 日目に花火が上がる場合 0 日後とする。
制約
- 1 \le M \le N \le 2 \times 10^5
- 1 \le A_1 < A_2 < \dots < A_M = N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_M
出力
N 行出力せよ。
i(1 \le i \le N) 行目には、i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後かを整数として出力せよ。
入力例 1
3 2 2 3
出力例 1
1 0 0
AtCoder 王国ではお祭りを 3 日間開催し、2,3 日目に花火が上がります。
- 1 日目以降で初めて花火が上がるのは 2 日目なので、1 日目から数えて 1 日後です。
- 2 日目以降で初めて花火が上がるのは 2 日目なので、2 日目から数えて 0 日後です。
- 3 日目以降で初めて花火が上がるのは 3 日目なので、3 日目から数えて 0 日後です。
入力例 2
8 5 1 3 4 7 8
出力例 2
0 1 0 0 2 1 0 0
Score : 250 points
Problem Statement
The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1-th, A_2-th, \dots, A_M-th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.)
For each i=1,2,\dots,N, solve the following problem.
- How many days later from the i-th day will fireworks be launched for the first time on or after the i-th day? If fireworks are launched on the i-th day, it is considered to be 0 days later.
Constraints
- 1 \le M \le N \le 2 \times 10^5
- 1 \le A_1 < A_2 < \dots < A_M = N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_M
Output
Print N lines.
The i-th line (1 \le i \le N) should contain an integer representing the number of days from the i-th day until fireworks are launched for the first time on or after the i-th day.
Sample Input 1
3 2 2 3
Sample Output 1
1 0 0
The kingdom holds a festival for 3 days, and fireworks are launched on the 2-nd and 3-rd days.
- From the 1-st day, the first time fireworks are launched is the 2-nd day of the festival, which is 1 day later.
- From the 2-nd day, the first time fireworks are launched is the 2-nd day of the festival, which is 0 days later.
- From the 3-rd day, the first time fireworks are launched is the 3-rd day of the festival, which is 0 days later.
Sample Input 2
8 5 1 3 4 7 8
Sample Output 2
0 1 0 0 2 1 0 0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は風船で空を飛ぶことにしました。高橋君は時刻 0 (単位は秒) の時点で高度 H にいて、これから 10^9 秒間飛行します。
高橋君は自身が飛んでいる高度を 1 秒あたり 1 まで変化させることが出来ます。ただし、高度を 0 以下にすることはできません。
- 言い換えると、高橋君の時刻 t における高度を F(t) とした時、F(t) は以下の条件を全て満たします。
- F(0) = H
- 0 \leq t \lt u \leq 10^9 において -1 \leq \dfrac{F(u) - F(t)}{u - t} \leq 1
- 0 \leq t \leq 10^9 において F(t) \gt 0
N 個の高度に関する目標があります。i 個目の目標は時刻 t_i 時点での高度を l_i 以上 u_i 以下にすることです。
高橋君は目標を全て達成するような飛行が可能ですか?
T 個のテストケースが与えられるので、それぞれに対して答えを求めてください。
制約
- 1 \leq T \leq 10^5
- 1 \leq N \leq 10^5
- 1 \leq H \leq 10^9
- 1 \leq t_1 \lt t_2 \lt \dots \lt t_N \leq 10^9
- 1 \leq l_i \leq u_i \leq 10^9
- 全てのテストケースにおける N の総和は 10^5 以下
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。ここで \mathrm{case}_i は i 番目のテストケースを意味する。
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
各テストケースは以下の形式で与えられる。
N H t_1 l_1 u_1 t_2 l_2 u_2 \vdots t_N l_N u_N
出力
T 行出力せよ。i 行目には、i 番目のテストケースにおいて目標を全て達成するような飛行が可能である場合 Yes を、そうでない場合 No を出力せよ。
入力例 1
3 2 5 3 1 4 8 9 11 2 6 1 1 4 3 5 8 10 36 27 37 38 30 34 54 38 20 77 45 1 36 49 38 51 52 31 58 65 43 60 71 14 42 73 36 38 85 14 29
出力例 1
Yes No Yes
1 番目のテストケースについて、高橋君は以下の方法で飛行することで全ての目標を達成することが出来ます。
- 時刻 0 の時点で高橋君は高度 5 にいる。
- 時刻 0 から時刻 2 にかけて高橋君は秒速 0.5 で高度を下げる。
- 時刻 2 の時点で高橋君は高度 5 - 0.5 \times 2 = 4 にいる。
- 時刻 2 から時刻 3 の間、高橋君は同じ高度にとどまる。
- 時刻 3 の時点で高橋君は高度 4 にいる。高橋君は 1 番目の目標を満たす。
- 時刻 3 から時刻 8 にかけて高橋君は秒速 1 で高度を上げる。
- 時刻 8 の時点で高橋君は高度 4 + 1 \times 5 = 9 にいる。高橋君は 2 番目の目標を満たす。
2 番目のテストケースについて、高橋君はどのように飛行しても目標を全て達成することは出来ません。
Score : 300 points
Problem Statement
Takahashi has decided to fly in the sky with balloons. Takahashi is at altitude H at time 0 (the unit is seconds), and will fly for 10^9 seconds from now.
Takahashi can change his flying altitude by up to 1 per second. However, he cannot make his altitude 0 or less.
- In other words, if F(t) denotes Takahashi's altitude at time t, then F(t) satisfies all of the following conditions:
- F(0) = H
- -1 \leq \dfrac{F(u) - F(t)}{u - t} \leq 1 for 0 \leq t \lt u \leq 10^9.
- F(t) \gt 0 for 0 \leq t \leq 10^9.
There are N goals regarding altitude. The i-th goal is to make the altitude at time t_i at least l_i and at most u_i.
Is it possible for Takahashi to fly in a way that achieves all goals?
You are given T test cases; solve each of them.
Constraints
- 1 \leq T \leq 10^5
- 1 \leq N \leq 10^5
- 1 \leq H \leq 10^9
- 1 \leq t_1 \lt t_2 \lt \dots \lt t_N \leq 10^9
- 1 \leq l_i \leq u_i \leq 10^9
- The sum of N over all test cases is at most 10^5.
- All input values are integers.
Input
The input is given from Standard Input in the following format, where \mathrm{case}_i denotes the i-th test case.
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Each test case is given in the following format:
N H t_1 l_1 u_1 t_2 l_2 u_2 \vdots t_N l_N u_N
Output
Output T lines. The i-th line should contain Yes if it is possible to fly in a way that achieves all goals in the i-th test case, and No otherwise.
Sample Input 1
3 2 5 3 1 4 8 9 11 2 6 1 1 4 3 5 8 10 36 27 37 38 30 34 54 38 20 77 45 1 36 49 38 51 52 31 58 65 43 60 71 14 42 73 36 38 85 14 29
Sample Output 1
Yes No Yes
For the first test case, Takahashi can achieve all goals by flying as follows:
- At time 0, he is at altitude 5.
- From time 0 to time 2, he descends at a rate of 0.5 per second.
- At time 2, he is at altitude 5 - 0.5 \times 2 = 4.
- From time 2 to time 3, he stays at the same altitude.
- At time 3, he is at altitude 4. He satisfies the first goal.
- From time 3 to time 8, he ascends at a rate of 1 per second.
- At time 8, he is at altitude 4 + 1 \times 5 = 9. He satisfies the second goal.
For the second test case, he cannot achieve all goals no matter how he flies.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
正整数 N と、 1 \leq x,y,z \leq N を満たす整数の組 (x,y,z) に対して、整数 A_{x,y,z} が与えられます。
次の形式の Q 個のクエリが与えられるので、それぞれに答えてください。
i 個目 (1 \leq i \leq Q) のクエリでは 1 \leq Lx_i \leq Rx_i \leq N, 1 \leq Ly_i \leq Ry_i \leq N,1 \leq Lz_i \leq Rz_i \leq N をすべて満たす整数の組 (Lx_i, Rx_i, Ly_i, Ry_i, Lz_i, Rz_i) が与えられるので、
\displaystyle{\sum_{x=Lx_i}^{Rx_i} \sum_{y=Ly_i}^{Ry_i} \sum_{z=Lz_i}^{Rz_i} A_{x,y,z}}
を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq Q \leq 2 \times 10^{5}
- 0 \leq A_{x,y,z} \leq 999 (1 \leq x,y,z \leq N)
- 1 \leq Lx_i \leq Rx_i \leq N (1 \leq i \leq Q)
- 1 \leq Ly_i \leq Ry_i \leq N (1 \leq i \leq Q)
- 1 \leq Lz_i \leq Rz_i \leq N (1 \leq i \leq Q)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_{1,1,1} A_{1,1,2} \ldots A_{1,1,N}
A_{1,2,1} A_{1,2,2} \ldots A_{1,2,N}
\vdots
A_{1,N,1} A_{1,N,2} \ldots A_{1,N,N}
A_{2,1,1} A_{2,1,2} \ldots A_{2,1,N}
A_{2,2,1} A_{2,2,2} \ldots A_{2,2,N}
\vdots
A_{2,N,1} A_{2,N,2} \ldots A_{2,N,N}
\vdots
A_{N,1,1} A_{N,1,2} \ldots A_{N,1,N}
A_{N,2,1} A_{N,2,2} \ldots A_{N,2,N}
\vdots
A_{N,N,1} A_{N,N,2} \ldots A_{N,N,N}
Q
Lx_1 Rx_1 Ly_1 Ry_1 Lz_1 Rz_1
Lx_2 Rx_2 Ly_2 Ry_2 Lz_2 Rz_2
\vdots
Lx_Q Rx_Q Ly_Q Ry_Q Lz_Q Rz_Q
出力
Q 行出力せよ。 i 行目には i 個目のクエリに対する答えを出力せよ。
入力例 1
2 1 2 3 4 5 6 7 8 2 1 2 2 2 1 1 2 2 1 2 1 2
出力例 1
10 26
1 個目のクエリについて、求めるべき値は A_{1,2,1}+A_{2,2,1}=3+7=10 です。よって、10 を出力します。
2 個目のクエリについて、求めるべき値は A_{2,1,1}+A_{2,1,2}+A_{2,2,1}+A_{2,2,2}=5+6+7+8=26 です。よって、26 を出力します。
入力例 2
3 733 857 714 956 208 257 123 719 648 840 881 245 245 112 746 306 942 694 58 870 849 13 208 789 687 906 783 8 3 3 3 3 1 1 1 3 2 3 3 3 2 2 2 3 1 1 1 3 1 1 1 1 2 3 2 3 2 3 1 2 1 1 1 2 3 3 2 2 1 3 1 2 2 3 2 3
出力例 2
687 3917 551 1631 5180 3311 1010 4326
Score : 400 points
Problem Statement
You are given a positive integer N, and an integer A_{x,y,z} for each triple of integers (x, y, z) such that 1 \leq x, y, z \leq N.
You will be given Q queries in the following format, which must be processed in order.
For the i-th query (1 \leq i \leq Q), you are given a tuple of integers (Lx_i, Rx_i, Ly_i, Ry_i, Lz_i, Rz_i) such that 1 \leq Lx_i \leq Rx_i \leq N, 1 \leq Ly_i \leq Ry_i \leq N, and 1 \leq Lz_i \leq Rz_i \leq N. Find:
\displaystyle{\sum_{x=Lx_i}^{Rx_i} \sum_{y=Ly_i}^{Ry_i} \sum_{z=Lz_i}^{Rz_i} A_{x,y,z}}.
Constraints
- 1 \leq N \leq 100
- 1 \leq Q \leq 2 \times 10^{5}
- 0 \leq A_{x,y,z} \leq 999 (1 \leq x, y, z \leq N)
- 1 \leq Lx_i \leq Rx_i \leq N (1 \leq i \leq Q)
- 1 \leq Ly_i \leq Ry_i \leq N (1 \leq i \leq Q)
- 1 \leq Lz_i \leq Rz_i \leq N (1 \leq i \leq Q)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_{1,1,1} A_{1,1,2} \ldots A_{1,1,N}
A_{1,2,1} A_{1,2,2} \ldots A_{1,2,N}
\vdots
A_{1,N,1} A_{1,N,2} \ldots A_{1,N,N}
A_{2,1,1} A_{2,1,2} \ldots A_{2,1,N}
A_{2,2,1} A_{2,2,2} \ldots A_{2,2,N}
\vdots
A_{2,N,1} A_{2,N,2} \ldots A_{2,N,N}
\vdots
A_{N,1,1} A_{N,1,2} \ldots A_{N,1,N}
A_{N,2,1} A_{N,2,2} \ldots A_{N,2,N}
\vdots
A_{N,N,1} A_{N,N,2} \ldots A_{N,N,N}
Q
Lx_1 Rx_1 Ly_1 Ry_1 Lz_1 Rz_1
Lx_2 Rx_2 Ly_2 Ry_2 Lz_2 Rz_2
\vdots
Lx_Q Rx_Q Ly_Q Ry_Q Lz_Q Rz_Q
Output
Print Q lines. The i-th line should contain the answer to the i-th query.
Sample Input 1
2 1 2 3 4 5 6 7 8 2 1 2 2 2 1 1 2 2 1 2 1 2
Sample Output 1
10 26
For the 1st query, the sought value is A_{1,2,1} + A_{2,2,1} = 3 + 7 = 10. Thus, print 10.
For the 2nd query, the sought value is A_{2,1,1} + A_{2,1,2} + A_{2,2,1} + A_{2,2,2} = 5 + 6 + 7 + 8 = 26. Thus, print 26.
Sample Input 2
3 733 857 714 956 208 257 123 719 648 840 881 245 245 112 746 306 942 694 58 870 849 13 208 789 687 906 783 8 3 3 3 3 1 1 1 3 2 3 3 3 2 2 2 3 1 1 1 3 1 1 1 1 2 3 2 3 2 3 1 2 1 1 1 2 3 3 2 2 1 3 1 2 2 3 2 3
Sample Output 2
687 3917 551 1631 5180 3311 1010 4326
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 475 点
問題文
長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。A の要素は相異なります。
Q 個のクエリが与えられるので順に処理してください。各クエリは次の 2 種類のどちらかです。
1 x y: A 内の要素 x の直後に y を挿入する。このクエリが与えられる時点で、A には x が存在することが保証される。2 x: A 内の要素 x を削除する。このクエリが与えられる時点で、A には x が存在することが保証される。
各クエリの処理後、A は空でなく、要素は相異なることが保証されます。
全てのクエリを処理した後の A を出力してください。
制約
- 1 \leq N \leq 2\times 10^5
- 1 \leq Q \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i \neq A_j
- 1 種類目のクエリにおいて、1 \leq x,y \leq 10^9
- 1 種類目のクエリが与えられる時点で、A には x が存在する
- 2 種類目のクエリにおいて、1 \leq x \leq 10^9
- 2 種類目のクエリが与えられる時点で、A には x が存在する
- 各クエリの処理後、A は空でなく、要素は相異なる
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 \ldots A_N
Q
\mathrm{Query}_1
\vdots
\mathrm{Query}_Q
ここで \mathrm{Query}_i は i 番目のクエリを表し、次の形式で与えられる。
1 x y
2 x
出力
全てのクエリを処理したあとの数列 A を (A_1,\ldots,A_K) とする。A_1,\ldots,A_K をこの順に空白区切りで出力せよ。
入力例 1
4 2 1 4 3 4 2 1 1 4 5 2 2 1 5 1
出力例 1
4 5 1 3
クエリは次のように処理されます。
- 最初 A=(2,1,4,3) である。
- 1 番目のクエリにより 1 を削除する。A=(2,4,3) となる。
- 2 番目のクエリにより、4 の直後に 5 を挿入する。A=(2,4,5,3) となる。
- 3 番目のクエリにより 2 を削除する。A=(4,5,3) となる。
- 4 番目のクエリにより、5 の直後に 1 を挿入する。A=(4,5,1,3) となる。
入力例 2
6 3 1 4 5 9 2 7 2 5 1 3 5 1 9 7 2 9 2 3 1 2 3 2 4
出力例 2
5 1 7 2 3
Score: 475 points
Problem Statement
You are given a sequence A=(A_1,\ldots,A_N) of length N. The elements of A are distinct.
Process Q queries in the order they are given. Each query is of one of the following two types:
1 x y: Insert y immediately after the element x in A. It is guaranteed that x exists in A when this query is given.2 x: Remove the element x from A. It is guaranteed that x exists in A when this query is given.
It is guaranteed that after processing each query, A will not be empty, and its elements will be distinct.
Print A after processing all the queries.
Constraints
- 1 \leq N \leq 2\times 10^5
- 1 \leq Q \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- A_i \neq A_j
- For queries of the first type, 1 \leq x,y \leq 10^9.
- When a query of the first type is given, x exists in A.
- For queries of the second type, 1 \leq x \leq 10^9.
- When a query of the second type is given, x exists in A.
- After processing each query, A is not empty, and its elements are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 \ldots A_N
Q
\mathrm{Query}_1
\vdots
\mathrm{Query}_Q
Here, \mathrm{Query}_i represents the i-th query and is given in one of the following formats:
1 x y
2 x
Output
Let A=(A_1,\ldots,A_K) be the sequence after processing all the queries. Print A_1,\ldots,A_K in this order, separated by spaces.
Sample Input 1
4 2 1 4 3 4 2 1 1 4 5 2 2 1 5 1
Sample Output 1
4 5 1 3
The queries are processed as follows:
- Initially, A=(2,1,4,3).
- The first query removes 1, making A=(2,4,3).
- The second query inserts 5 immediately after 4, making A=(2,4,5,3).
- The third query removes 2, making A=(4,5,3).
- The fourth query inserts 1 immediately after 5, making A=(4,5,1,3).
Sample Input 2
6 3 1 4 5 9 2 7 2 5 1 3 5 1 9 7 2 9 2 3 1 2 3 2 4
Sample Output 2
5 1 7 2 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
整数 N が与えられます。
次の条件を全て満たす文字列 S としてあり得るものを 1 個出力してください。そのような文字列が存在しなければ -1 を出力してください。
- S は
1,2,3,4,5,6,7,8,9および*(乗算記号) からなる長さ 1 以上 1000 以下の文字列である。 - S は回文である。
- S の先頭の文字は数字である。
- S を式として評価した値が N と一致する。
制約
- 1 \leq N \leq 10^{12}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
問題文の条件を満たす文字列が存在する場合はその文字列を、そうでない場合は -1 を出力せよ。
入力例 1
363
出力例 1
11*3*11
S = 11*3*11 は問題文の条件を満たします。他に条件を満たす文字列として S= 363 があります。
入力例 2
101
出力例 2
-1
S は 0 を含んではいけない点に注意してください。
入力例 3
3154625100
出力例 3
2*57*184481*75*2
Score : 500 points
Problem Statement
You are given an integer N. Print a string S that satisfies all of the following conditions. If no such string exists, print -1.
- S is a string of length between 1 and 1000, inclusive, consisting of the characters
1,2,3,4,5,6,7,8,9, and*(multiplication symbol). - S is a palindrome.
- The first character of S is a digit.
- The value of S when evaluated as a formula equals N.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
If there is a string S that satisfies the conditions exists, print such a string. Otherwise, print -1.
Sample Input 1
363
Sample Output 1
11*3*11
S = 11*3*11 satisfies the conditions in the problem statement. Another string that satisfies the conditions is S= 363.
Sample Input 2
101
Sample Output 2
-1
Note that S must not contain the digit 0.
Sample Input 3
3154625100
Sample Output 3
2*57*184481*75*2