Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君が 100 階建てのビルにいます。
高橋君は 2 階分までの上り、または、3 階分までの下りであれば移動には階段を使い、そうでないときエレベーターを使います。
高橋君が X 階から Y 階への移動に使うのは階段ですか?
制約
- 1 \leq X,Y \leq 100
- X \neq Y
- 入力は全ては整数である
入力
入力は以下の形式で標準入力から与えられる。
X Y
出力
移動に使うのが階段ならば Yes、エレベーターならば No を出力せよ。
入力例 1
1 4
出力例 1
No
1 階から 4 階への移動は 3 階分の上りなのでエレベーターを使います。
入力例 2
99 96
出力例 2
Yes
99 階から 96 階への移動は 3 階分の下りなので階段を使います。
入力例 3
100 1
出力例 3
No
Score : 100 points
Problem Statement
Takahashi is in a building with 100 floors.
He uses the stairs for moving up two floors or less or moving down three floors or less, and uses the elevator otherwise.
Does he use the stairs to move from floor X to floor Y?
Constraints
- 1 \leq X,Y \leq 100
- X \neq Y
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X Y
Output
If Takahashi uses the stairs for the move, print Yes; if he uses the elevator, print No.
Sample Input 1
1 4
Sample Output 1
No
The move from floor 1 to floor 4 involves going up three floors, so Takahashi uses the elevator.
Sample Input 2
99 96
Sample Output 2
Yes
The move from floor 99 to floor 96 involves going down three floors, so Takahashi uses the stairs.
Sample Input 3
100 1
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
0 と 1 からなる長さ 16 の文字列 S が与えられます。
2 以上 16 以下のすべての偶数 i について S の i 文字目が 0 ならば Yes を、
そうでないならば No を出力してください。
制約
- S は
0と1からなる長さ 16 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
2 以上 16 以下のすべての偶数 i について S の i 文字目が 0 ならば Yes を、
そうでないならば No を出力せよ。
入力例 1
1001000000001010
出力例 1
No
S= 1001000000001010 の 4 文字目が 1 であるため、No を出力します。
入力例 2
1010100000101000
出力例 2
Yes
S= 1010100000101000 の偶数番目の文字はすべて 0 であるため、Yes を出力します。
入力例 3
1111111111111111
出力例 3
No
S の偶数文字目はすべて 1 となっています。
特に「すべて 0 」ではないため、No を出力します。
Score : 100 points
Problem Statement
You are given a string S of length 16 consisting of 0 and 1.
If the i-th character of S is 0 for every even number i from 2 through 16, print Yes; otherwise, print No.
Constraints
- S is a string of length 16 consisting of
0and1.
Input
The input is given from Standard Input in the following format:
S
Output
If the i-th character of S is 0 for every even number i from 2 through 16, print Yes; otherwise, print No.
Sample Input 1
1001000000001010
Sample Output 1
No
The 4-th character of S= 1001000000001010 is 1, so you should print No.
Sample Input 2
1010100000101000
Sample Output 2
Yes
Every even-positioned character in S= 1010100000101000 is 0, so you should print Yes.
Sample Input 3
1111111111111111
Sample Output 3
No
Every even-positioned character in S is 1.
Particularly, they are not all 0, so you should print No.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
数字のみからなる長さ 6 の文字列が N 個与えられます。i \, (i = 1, 2, \dots, N) 番目のものを S_i と表します。
さらに、数字のみからなる長さ 3 の文字列が M 個与えられます。j \, (j = 1, 2, \dots, M) 番目のものを T_j と表します。
S_1, S_2, \dots, S_N のうち、末尾 3 文字が T_1, T_2, \dots, T_M のいずれかに一致するものの個数を求めてください。
制約
- 1 \leq N, M \leq 1000
- N, M は整数
- 全ての i = 1, 2, \dots, N に対し、S_i は数字のみからなる長さ 6 の文字列
- 全ての j = 1, 2, \dots, M に対し、T_j は数字のみからなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
出力
答えを出力せよ。
入力例 1
3 3 142857 004159 071028 159 287 857
出力例 1
2
S_1 の末尾 3 文字は 857 であり、これは T_3 に一致します。
S_2 の末尾 3 文字は 159 であり、これは T_1 に一致します。
S_3 の末尾 3 文字は 028 であり、これは T_1, T_2, T_3 のいずれにも一致しません。
以上から、答えは 2 です。
入力例 2
5 4 235983 109467 823476 592801 000333 333 108 467 983
出力例 2
3
入力例 3
4 4 000000 123456 987111 000000 000 111 999 111
出力例 3
3
Score : 200 points
Problem Statement
You are given N strings of length six each, consisting of digits. Let S_i be the i-th (i = 1, 2, \dots, N) of them.
You are also given M strings of length three each, consisting of digits. Let T_j be the j-th (j = 1, 2, \dots, M) of them.
Find the number of strings among S_1, S_2, \dots, S_N whose last three characters coincide with one or more of T_1, T_2, \dots, T_M.
Constraints
- 1 \leq N, M \leq 1000
- N and M are integers.
- S_i is a string of length 6 consisting of digits, for all i = 1, 2, \dots, N.
- T_j is a string of length 3 consisting of digits, for all j = 1, 2, \dots, M.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
Output
Print the answer.
Sample Input 1
3 3 142857 004159 071028 159 287 857
Sample Output 1
2
The last three characters of S_1 are 857, which coincide with T_3.
The last three characters of S_2 are 159, which coincide with T_1.
The last three characters of S_3 are 028, which do not coincide with T_1, T_2, or T_3.
Thus, the answer is 2.
Sample Input 2
5 4 235983 109467 823476 592801 000333 333 108 467 983
Sample Output 2
3
Sample Input 3
4 4 000000 123456 987111 000000 000 111 999 111
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は体操の大会に参加しています。
大会では、5N 人の審査員それぞれが高橋君の演技に対して評点をつけ、それらを元に次のように高橋君の得点が決定されます。
- 高い評点をつけた方から順に N 人の審査員による評点を無効にする。
- 低い評点をつけた方から順に N 人の審査員による評点を無効にする。
- 残りの 3N 人の審査員による評点の平均点を高橋君の得点とする。
より厳密には、審査員がつけた得点の多重集合 S (|S|=5N) に対して次の操作を行って得られたものが高橋君の得点となります。
- 「S の最大の要素(複数ある場合はそのうちの 1 つ)を選び、S から取り除く」という操作を N 回繰り返す。
- 「S の最小の要素(複数ある場合はそのうちの 1 つ)を選び、S から取り除く」という操作を N 回繰り返す。
- S に残った 3N 個の要素の平均を高橋君の得点とする。
高橋君の演技に対する、i 人目 (1\leq i\leq 5N) の審査員の評点は X_i 点でした。 高橋君の得点を計算してください。
制約
- 1\leq N\leq 100
- 0\leq X_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N
X_1 X_2 \ldots X_{5N}
出力
高橋君の得点を出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-5} 以下であれば正解として扱われる。
入力例 1
1 10 100 20 50 30
出力例 1
33.333333333333336
N=1 であるので、評点が高い方と低い方からそれぞれ 1 人ずつの審査員による評点を無効にします。
1 番高い評点をつけた審査員は 2 人目 (100 点) であるため、これを無効にします。
また、1 番低い評点をつけた審査員は 1 人目 (10 点) であるため、これも無効にします。
よって、最終的な平均点は \displaystyle\frac{20+50+30}{3}=33.333\cdots となります。
出力は、真の値との絶対誤差または相対誤差が 10^{-5} 以下であれば正解として扱われる事に注意してください。
入力例 2
2 3 3 3 4 5 6 7 8 99 100
出力例 2
5.500000000000000
N=2 であるので、評点が高い方と低い方からそれぞれ 2 人ずつの審査員による評点を無効にします。
1,2 番目に高い評点をつけた審査員は順に 10 人目 (100 点), 9 人目 (99 点) であるため、これを無効にします。
1 番低い評点をつけた審査員は 1,2,3 人目 (3 点) の 3 人がいるため、このうち 2 人を無効とします。
よって、答えは \displaystyle\frac{3+4+5+6+7+8}{6}=5.5 となります。
1 番低い評点をつけた 3 人のうちどの 2 人を無効にしたかは、答えに影響しない事に注意してください。
Score : 200 points
Problem Statement
Takahashi is participating in a gymnastic competition.
In the competition, each of 5N judges grades Takahashi's performance, and his score is determined as follows:
- Invalidate the grades given by the N judges who gave the highest grades.
- Invalidate the grades given by the N judges who gave the lowest grades.
- Takahashi's score is defined as the average of the remaining 3N judges' grades.
More formally, Takahashi's score is obtained by performing the following procedure on the multiset of the judges' grades S (|S|=5N):
- Repeat the following operation N times: choose the maximum element (if there are multiple such elements, choose one of them) and remove it from S.
- Repeat the following operation N times: choose the minimum element (if there are multiple such elements, choose one of them) and remove it from S.
- Takahashi's score is defined as the average of the 3N elements remaining in S.
The i-th (1\leq i\leq 5N) judge's grade for Takahashi's performance was X_i points. Find Takahashi's score.
Constraints
- 1\leq N\leq 100
- 0\leq X_i\leq 100
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
X_1 X_2 \ldots X_{5N}
Output
Print Takahashi's score.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.
Sample Input 1
1 10 100 20 50 30
Sample Output 1
33.333333333333336
Since N=1, the grade given by one judge who gave the highest grade, and one with the lowest, are invalidated.
The 2-nd judge gave the highest grade (100 points), which is invalidated.
Additionally, the 1-st judge gave the lowest grade (10 points), which is also invalidated.
Thus, the average is \displaystyle\frac{20+50+30}{3}=33.333\cdots.
Note that the output will be considered correct if the absolute or relative error from the true value is at most 10^{-5}.
Sample Input 2
2 3 3 3 4 5 6 7 8 99 100
Sample Output 2
5.500000000000000
Since N=2, the grades given by the two judges who gave the highest grades, and two with the lowest, are invalidated.
The 10-th and 9-th judges gave the highest grades (100 and 99 points, respectively), which are invalidated.
Three judges, the 1-st, 2-nd, and 3-rd, gave the lowest grade (3 points), so two of them are invalidated.
Thus, the average is \displaystyle\frac{3+4+5+6+7+8}{6}=5.5.
Note that the choice of the two invalidated judges from the three with the lowest grades does not affect the answer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の整数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。
整数の 2 つ組 (i,j)\ (1\le i\lt j\le N) のうち、j-i=A _ i+A _ j を満たすものがいくつあるか求めてください。
制約
- 1\le N\le2\times10 ^ 5
- 1\le A _ i\le2\times10 ^ 5\ (1\le i\le N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A _ 1 A _ 2 \ldots A _ N
出力
答えを出力せよ。
入力例 1
9 3 1 4 1 5 9 2 6 5
出力例 1
3
例えば、(i,j)=(4,7) とすると、j-i=7-4=3 かつ A _ i+A _ j=1+2=3 が成り立つので、j-i=A _ i+A _ j です。
一方で、(i,j)=(3,8) とすると、j-i=8-3=5 かつ A _ i+A _ j=4+6=10 となるので、j-i\ne A _ i+A _ j です。
(i,j)=(1,9),(2,4),(4,7) の 3 組だけが条件を満たすので、3 を出力してください。
入力例 2
3 123456 123456 123456
出力例 2
0
条件を満たす組が存在しない場合もあります。
入力例 3
30 8 3 6 4 9 6 5 6 5 6 3 4 7 3 7 4 9 8 5 8 3 6 8 8 4 5 5 5 6 5
出力例 3
17
Score : 300 points
Problem Statement
You are given an integer sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.
Find how many pairs of integers (i,j)\ (1\le i\lt j\le N) satisfy j-i=A _ i+A _ j.
Constraints
- 1\le N\le2\times10 ^ 5
- 1\le A _ i\le2\times10 ^ 5\ (1\le i\le N)
- 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
Output
Output the answer.
Sample Input 1
9 3 1 4 1 5 9 2 6 5
Sample Output 1
3
For example, when (i,j)=(4,7), we have j-i=7-4=3 and A _ i+A _ j=1+2=3, so j-i=A _ i+A _ j.
In contrast, when (i,j)=(3,8), we have j-i=8-3=5 and A _ i+A _ j=4+6=10, so j-i\ne A _ i+A _ j.
Only the three pairs (i,j)=(1,9),(2,4),(4,7) satisfy the condition, so output 3.
Sample Input 2
3 123456 123456 123456
Sample Output 2
0
There may be no pairs that satisfy the condition.
Sample Input 3
30 8 3 6 4 9 6 5 6 5 6 3 4 7 3 7 4 9 8 5 8 3 6 8 8 4 5 5 5 6 5
Sample Output 3
17
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
WAtCoder には N 人のユーザがおり、1 から N までの番号がつけられています。 また、M 個のコンテストページがあり、1 から M までの番号がつけられています。 はじめ、すべてのユーザはどのコンテストページの閲覧権限も持っていません。
Q 個のクエリが与えられるので、順に処理してください。クエリは 3 種類あり、以下のいずれかの形式で与えられます。
1 X Y: ユーザ X にコンテストページ Y の閲覧権限を付与する。2 X: ユーザ X にすべてのコンテストページの閲覧権限を付与する。3 X Y: ユーザ X がコンテストページ Y を閲覧できるかを答える。
クエリの中で、あるユーザがすでに閲覧権限を持っているコンテストページについて、重ねて閲覧権限を付与されることもあります。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq X \leq N
- 1 \leq Y \leq M
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
各クエリ \mathrm{query}_i は以下の 3 種類のいずれかの形式で与えられる。
1 X Y
2 X
3 X Y
出力
3 種類目のクエリのそれぞれについて、ユーザ X がコンテストページ Y を閲覧できるならば Yes を、そうでなければ No を改行区切りで出力せよ。
入力例 1
2 3 5 1 1 2 3 1 1 3 1 2 2 2 3 2 3
出力例 1
No Yes Yes
- 1 つ目のクエリで、ユーザ 1 にコンテストページ 2 の閲覧権限を付与します。
- 2 つ目のクエリの時点で、ユーザ 1 が閲覧できるコンテストページは 2 のみです。コンテストページ 1 の閲覧権限を持っていないので、
Noを出力します。 - 3 つ目のクエリの時点で、ユーザ 1 はコンテストページ 2 の閲覧権限を持っているので、
Yesを出力します。 - 4 つ目のクエリで、ユーザ 2 にすべてのコンテストページの閲覧権限を付与します。
- 5 つ目のクエリの時点で、ユーザ 2 が閲覧できるコンテストページは 1,2,3 です。コンテストページ 3 の閲覧権限を持っているので、
Yesを出力します。
入力例 2
5 5 10 2 2 3 4 4 1 1 1 1 4 1 1 4 2 1 4 4 1 2 4 3 3 2 3 5 4 3 2 1
出力例 2
No No No Yes
Score : 300 points
Problem Statement
There are N users on WAtCoder, numbered from 1 to N, and M contest pages, numbered from 1 to M. Initially, no user has view permission for any contest page.
You are given Q queries to process in order. Each query is of one of the following three types:
1 X Y: Grant user X view permission for contest page Y.2 X: Grant user X view permission for all contest pages.3 X Y: Answer whether user X can view contest page Y.
It is possible for a user to be granted permission for the same contest page multiple times.
Constraints
- 1 \le N \le 2\times 10^5
- 1 \le M \le 2\times 10^5
- 1 \le Q \le 2\times 10^5
- 1 \le X \le N
- 1 \le Y \le M
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Each \mathrm{query}_i is in one of the following formats:
1 X Y
2 X
3 X Y
Output
For each query of the third type, print Yes if user X can view contest page Y, otherwise print No, each on its own line.
Sample Input 1
2 3 5 1 1 2 3 1 1 3 1 2 2 2 3 2 3
Sample Output 1
No Yes Yes
- In the first query, user 1 is granted permission to view contest page 2.
- At the second query, user 1 can view only page 2; they cannot view page 1, so print
No. - At the third query, user 1 can view page 2, so print
Yes. - In the fourth query, user 2 is granted permission to view all pages.
- At the fifth query, user 2 can view pages 1,2,3; they can view page 3, so print
Yes.
Sample Input 2
5 5 10 2 2 3 4 4 1 1 1 1 4 1 1 4 2 1 4 4 1 2 4 3 3 2 3 5 4 3 2 1
Sample Output 2
No No No Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
頂点に 1 から N の番号が付いた N 頂点の重み付き無向完全グラフが与えられます。頂点 i と頂点 j\ (i< j) を結ぶ辺の重みは D_{i,j} です。
以下の条件を満たすように何本かの辺を選ぶとき、選んだ辺の重みの総和としてあり得る最大値を求めてください。
- 選んだ辺の端点はどの 2 個も相異なる。
制約
- 2\leq N\leq 16
- 1\leq D_{i,j} \leq 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
D_{1,2} D_{1,3} \ldots D_{1,N}
D_{2,3} \ldots D_{2,N}
\vdots
D_{N-1,N}
出力
答えを整数として出力せよ。
入力例 1
4 1 5 4 7 8 6
出力例 1
13
頂点 1 と頂点 3 を結ぶ辺、頂点 2 と頂点 4 を結ぶ辺を選ぶと、辺の重みの総和が 5+8=13 となります。
これが達成可能な最大値であることが示せます。
入力例 2
3 1 2 3
出力例 2
3
N が奇数の場合もあります。
入力例 3
16 5 6 5 2 1 7 9 7 2 5 5 2 4 7 6 8 7 7 9 8 1 9 6 10 8 8 6 10 3 10 5 8 1 10 7 8 4 8 6 5 1 10 7 4 1 4 5 4 5 10 1 5 1 2 2 9 9 7 6 2 2 8 3 5 2 9 10 3 1 1 2 10 7 7 5 10 6 1 8 9 3 2 4 2 10 10 8 9 2 10 7 9 5 8 8 7 5 8 2 4 2 2 6 8 3 2 7 3 10 3 5 7 10 3 8 5 7 9 1 4
出力例 3
75
Score : 400 points
Problem Statement
You are given a weighted undirected complete graph with N vertices numbered from 1 to N. The edge connecting vertices i and j (i< j) has a weight of D_{i,j}.
When choosing some number of edges under the following condition, find the maximum possible total weight of the chosen edges.
- The endpoints of the chosen edges are pairwise distinct.
Constraints
- 2\leq N\leq 16
- 1\leq D_{i,j} \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
D_{1,2} D_{1,3} \ldots D_{1,N}
D_{2,3} \ldots D_{2,N}
\vdots
D_{N-1,N}
Output
Print the answer as an integer.
Sample Input 1
4 1 5 4 7 8 6
Sample Output 1
13
If you choose the edge connecting vertices 1 and 3, and the edge connecting vertices 2 and 4, the total weight of the edges is 5+8=13.
It can be shown that this is the maximum achievable value.
Sample Input 2
3 1 2 3
Sample Output 2
3
N can be odd.
Sample Input 3
16 5 6 5 2 1 7 9 7 2 5 5 2 4 7 6 8 7 7 9 8 1 9 6 10 8 8 6 10 3 10 5 8 1 10 7 8 4 8 6 5 1 10 7 4 1 4 5 4 5 10 1 5 1 2 2 9 9 7 6 2 2 8 3 5 2 9 10 3 1 1 2 10 7 7 5 10 6 1 8 9 3 2 4 2 10 10 8 9 2 10 7 9 5 8 8 7 5 8 2 4 2 2 6 8 3 2 7 3 10 3 5 7 10 3 8 5 7 9 1 4
Sample Output 3
75
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
ストーリー
長い水槽があり、高さの異なる板が等間隔に配置されています。 高橋くんは、この水槽の端へ水を注いでいったとき、板で区切られたそれぞれの領域に水が到達する時刻が知りたいです。
問題文
長さ N の正整数列 H=(H _ 1,H _ 2,\dotsc,H _ N) が与えられます。
長さ N+1 の非負整数列 A=(A _ 0,A _ 1,\dotsc,A _ N) があります。 はじめ、A _ 0=A _ 1=\dotsb=A _ N=0 です。
A に対して、次の操作を繰り返します。
- A _ 0 の値を 1 増やす。
- i=1,2,\ldots,N に対して、この順に次の操作を行う。
- A _ {i-1}\gt A _ i かつ A _ {i-1}\gt H _ i のとき、A _ {i-1} の値を 1 減らし、A _ i の値を 1 増やす。
i=1,2,\ldots,N のそれぞれに対して、初めて A _ i>0 が成り立つのは何回目の操作の後か求めてください。
制約
- 1\leq N\leq2\times10 ^ 5
- 1\leq H _ i\leq10 ^ 9\ (1\leq i\leq N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N H _ 1 H _ 2 \dotsc H _ N
出力
i=1,2,\ldots,N に対する答えを、空白を区切りとして 1 行に出力せよ。
入力例 1
5 3 1 4 1 5
出力例 1
4 5 13 14 26
はじめ 5 回の操作では以下のようになります。
それぞれの行が一回の操作に対応し、左端が 1 番の操作を、それ以外が 2 番の操作に対応します。

この図から、A _ 1\gt0 が初めて成り立つのは 4 回目の操作の後、A _ 2\gt0 が初めて成り立つのは 5 回目の操作の後です。
同様にして、A _ 3,A _ 4,A _ 5 に対する答えは 13,14,26 です。
よって、4 5 13 14 26 を出力してください。
入力例 2
6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2
1000000001 2000000001 3000000001 4000000001 5000000001 6000000001
出力すべき値が 32\operatorname{bit} 整数に収まらない場合があることに注意してください。
入力例 3
15 748 169 586 329 972 529 432 519 408 587 138 249 656 114 632
出力例 3
749 918 1921 2250 4861 5390 5822 6428 6836 7796 7934 8294 10109 10223 11373
Score : 500 points
Story
There is a long water tank with boards of different heights placed at equal intervals. Takahashi wants to know the time at which water reaches each section separated by the boards when water is poured from one end of the tank.
Problem Statement
You are given a sequence of positive integers of length N: H=(H _ 1,H _ 2,\dotsc,H _ N).
There is a sequence of non-negative integers of length N+1: A=(A _ 0,A _ 1,\dotsc,A _ N). Initially, A _ 0=A _ 1=\dotsb=A _ N=0.
Perform the following operations repeatedly on A:
- Increase the value of A _ 0 by 1.
- For i=1,2,\ldots,N in this order, perform the following operation:
- If A _ {i-1}\gt A _ i and A _ {i-1}\gt H _ i, decrease the value of A _ {i-1} by 1 and increase the value of A _ i by 1.
For each i=1,2,\ldots,N, find the number of operations before A _ i>0 holds for the first time.
Constraints
- 1\leq N\leq2\times10 ^ 5
- 1\leq H _ i\leq10 ^ 9\ (1\leq i\leq N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N H _ 1 H _ 2 \dotsc H _ N
Output
Print the answers for i=1,2,\ldots,N in a single line, separated by spaces.
Sample Input 1
5 3 1 4 1 5
Sample Output 1
4 5 13 14 26
The first five operations go as follows.
Here, each row corresponds to one operation, with the leftmost column representing step 1 and the others representing step 2.

From this diagram, A _ 1\gt0 holds for the first time after the 4th operation, and A _ 2\gt0 holds for the first time after the 5th operation.
Similarly, the answers for A _ 3, A _ 4, A _ 5 are 13, 14, 26, respectively.
Therefore, you should print 4 5 13 14 26.
Sample Input 2
6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
1000000001 2000000001 3000000001 4000000001 5000000001 6000000001
Note that the values to be output may not fit within a 32-bit integer.
Sample Input 3
15 748 169 586 329 972 529 432 519 408 587 138 249 656 114 632
Sample Output 3
749 918 1921 2250 4861 5390 5822 6428 6836 7796 7934 8294 10109 10223 11373
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
T 個のテストケースについて、数字のみからなる文字列 S と正整数 L,R が与えられるので、以下の問題を解いてください。
正整数 x に対して f(x)= ( x を ( 先頭に 0 を含まないように ) 書き下した文字列の連続部分列のうち S と合致するものの個数 ) と定義します。
例えば S= 22 であるとき、f(122) = 1, f(123) = 0, f(226) = 1, f(222) = 2 となります。
このとき、 \displaystyle \sum_{k=L}^{R} f(k) を求めてください。
制約
- 1 \le T \le 1000
- S は数字のみからなる長さ 1 以上 16 以下の文字列
- L,R は 1 \le L \le R < 10^{16} を満たす整数
入力
入力は以下の形式で標準入力から与えられる。\rm{case}_i は i 個目のテストケースを表す。
T
\rm{case}_{1}
\rm{case}_{2}
\vdots
\rm{case}_{\it{T}}
各テストケースは以下の形式である。
S L R
出力
全体で T 行出力せよ。
そのうち i 行目には i 番目のテストケースに対する答えを整数として出力せよ。
入力例 1
6 22 23 234 0295 295 295 0 1 9999999999999999 2718 998244353 9982443530000000 869120 1234567890123456 2345678901234567 2023032520230325 1 9999999999999999
出力例 1
12 0 14888888888888889 12982260572545 10987664021 1
この入力には 6 個のテストケースが含まれます。
- 1 つ目のケースは S=
22,L=23,R=234 です。- f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1
- f(222)=2
- 以上より、このケースに対する答えは 12 です。
- 2 つ目のケースは S=
0295,L=295,R=295 です。- f(295)=0 となることに注意してください。
Score : 500 points
Problem Statement
You are given a string S consisting of digits and positive integers L and R for each of T test cases. Solve the following problem.
For a positive integer x, let us define f(x) as the number of contiguous substrings of the decimal representation of x (without leading zeros) that equal S.
For instance, if S= 22, we have f(122) = 1, f(123) = 0, f(226) = 1, and f(222) = 2.
Find \displaystyle \sum_{k=L}^{R} f(k).
Constraints
- 1 \le T \le 1000
- S is a string consisting of digits whose length is between 1 and 16, inclusive.
- L and R are integers satisfying 1 \le L \le R < 10^{16}.
Input
The input is given from Standard Input in the following format, where \rm{case}_i denotes the i-th test case:
T
\rm{case}_{1}
\rm{case}_{2}
\vdots
\rm{case}_{\it{T}}
Each test case is in the following format:
S L R
Output
Print T lines in total.
The i-th line should contain an integer representing the answer to the i-th test case.
Sample Input 1
6 22 23 234 0295 295 295 0 1 9999999999999999 2718 998244353 9982443530000000 869120 1234567890123456 2345678901234567 2023032520230325 1 9999999999999999
Sample Output 1
12 0 14888888888888889 12982260572545 10987664021 1
This input contains six test cases.
- In the first test case, S=
22, L=23, R=234.- f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1.
- f(222)=2.
- Thus, the answer is 12.
- In the second test case, S=
0295, L=295, R=295.- Note that f(295)=0.