Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 D が与えられます。
直径が D の円の面積を求めて下さい。
制約
- 1\le D\le 100
- 入力される値は整数
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。
真の解との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。
入力例 1
2
出力例 1
3.141592653589793
直径が 2 の円の面積は 3.141592653589793\ldots です。
入力例 2
7
出力例 2
38.48451000647496
入力例 3
98
出力例 3
7542.9639612690935
Score : 100 points
Problem Statement
You are given a positive integer D.
Find the area of a circle with diameter D.
Constraints
- 1\le D\le 100
- The input value is an integer.
Input
The input is given from Standard Input in the following format:
D
Output
Output the answer.
Your answer is considered correct if the absolute or relative error from the true answer is at most 10^{-6}.
Sample Input 1
2
Sample Output 1
3.141592653589793
The area of a circle with diameter 2 is 3.141592653589793\ldots.
Sample Input 2
7
Sample Output 2
38.48451000647496
Sample Input 3
98
Sample Output 3
7542.9639612690935
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
ある日、高橋君は A 時 B 分ちょうどに、青木君は C 時 D 分 1 秒に起きました。
高橋君の起床時刻が青木君より早いならば Takahashi を、そうでないならば Aoki を出力してください。
制約
- 0 \leq A \leq 23
- 0 \leq B \leq 59
- 0 \leq C \leq 23
- 0 \leq D \leq 59
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
A B C D
出力
高橋君の起床時刻が青木君より早いならば Takahashi を、そうでないならば Aoki を出力せよ。
入力例 1
7 0 6 30
出力例 1
Aoki
高橋君は 7 時ちょうどに、青木君は 6 時 30 分 1 秒に起きました。
青木君の起床時刻の方が早いため、Aoki を出力します。
入力例 2
7 30 7 30
出力例 2
Takahashi
高橋君は 7 時 30 分ちょうどに、青木君は 7 時 30 分 1 秒に起きました。
高橋君の起床時刻の方が 1 秒だけ早いため、Takahashi を出力します。
入力例 3
0 0 23 59
出力例 3
Takahashi
ある日の 0 時 0 分ちょうどはその日の 0 時 1 分の 1 分前であり、
その日の 23 時 59 分の 1 分後、すなわちいわゆる 24 時ちょうどのことではありません。
よって、高橋君の起床時刻の方が早く、Takahashi を出力します。
Score : 100 points
Problem Statement
One day, Takahashi got up at exactly B minutes past A o'clock (in 24-hour clock), and Aoki got up at exactly D minutes and 1 second past C o'clock.
If Takahashi got up earlier than Aoki, print Takahashi; otherwise, print Aoki.
Constraints
- 0 \leq A \leq 23
- 0 \leq B \leq 59
- 0 \leq C \leq 23
- 0 \leq D \leq 59
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
If Takahashi got up earlier than Aoki, print Takahashi; otherwise, print Aoki.
Sample Input 1
7 0 6 30
Sample Output 1
Aoki
Takahashi got up at 7 sharp, and Aoki got up at 30 minutes and 1 second past 6 o'clock.
Aoki was the first to get up, so Aoki should be printed.
Sample Input 2
7 30 7 30
Sample Output 2
Takahashi
Takahashi got up at exactly half past 7, and Aoki got up at 30 minutes and 1 second past 7 o'clock.
Just by one second, Takahashi was the first to get up, so Takahashi should be printed.
Sample Input 3
0 0 23 59
Sample Output 3
Takahashi
0:00 in a day is one minute before 0:01, not one minute past 23:59 ("24:00").
Thus, Takahashi was the first to get up, so Takahashi should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
I begin with T and end with T, and I am full of T. What am I?
文字列 t について、充填率を以下のように定義します。
- t の先頭と末尾の文字がともに
tであり、かつ |t| \geq 3 である場合: t に含まれるtの個数を x とすると、t の充填率は \displaystyle\frac{x-2}{|t|-2} である。ここで、|t| は t の長さを表す。 - そうでない場合: t の充填率は 0 である。
文字列 S が与えられます。S の部分文字列の充填率としてありうる最大値を求めてください。
部分文字列とは
S の部分文字列とは、S の先頭から 0 文字以上、末尾から 0 文字以上削除して得られる文字列のことをいいます。 例えば、ab, bc, bcd は abcd の部分文字列ですが、ac, dc, e は abcd の部分文字列ではありません。
制約
- 1 \leq |S| \leq 100
- S は英小文字からなる文字列。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の部分文字列の充填率としてありうる最大値を出力せよ。
出力された値と真の値との絶対誤差が 10^{-9} 以下のとき、正答と判定される。
入力例 1
attitude
出力例 1
0.50000000000000000
ttit は S の部分文字列であり、その充填率は \displaystyle\frac{3-2}{4-2} = \frac{1}{2} です。
充填率が \frac{1}{2} より高い部分文字列は存在しないので、答えは \frac{1}{2} です。
入力例 2
ottottott
出力例 2
0.66666666666666667
ttottott は S の部分文字列であり、その充填率は \displaystyle\frac{6-2}{8-2} = \frac{2}{3} です。
充填率が \frac{2}{3} より高い部分文字列は存在しないので、答えは \frac{2}{3} です。
入力例 3
coffeecup
出力例 3
0.00000000000000000
ff は S の部分文字列であり、その充填率は 0 です。
充填率が 0 より高い部分文字列は存在しないので、答えは 0 です。
Score : 200 points
Problem Statement
I begin with T and end with T, and I am full of T. What am I?
For a string t, define the filling rate as follows:
- If the first and last characters of t are both
tand |t| \geq 3: Let x be the number oftin t. Then the filling rate of t is \displaystyle\frac{x-2}{|t|-2}, where |t| denotes the length of t. - Otherwise: the filling rate of t is 0.
You are given a string S. Find the maximum possible filling rate of a substring of S.
What is a substring?
A substring of S is a string obtained by removing zero or more characters from the beginning and the end of S. For example,ab, bc, and bcd are substrings of abcd, while ac, dc, and e are not substrings of abcd.
Constraints
- 1 \leq |S| \leq 100
- S is a string consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print the maximum possible filling rate of a substring of S.
Your output will be judged as correct when the absolute error from the true value is at most 10^{-9}.
Sample Input 1
attitude
Sample Output 1
0.50000000000000000
ttit is a substring of S, and its filling rate is \displaystyle\frac{3-2}{4-2} = \frac{1}{2}.
There is no substring with a filling rate greater than \frac{1}{2}, so the answer is \frac{1}{2}.
Sample Input 2
ottottott
Sample Output 2
0.66666666666666667
ttottott is a substring of S, and its filling rate is \displaystyle\frac{6-2}{8-2} = \frac{2}{3}.
There is no substring with a filling rate greater than \frac{2}{3}, so the answer is \frac{2}{3}.
Sample Input 3
coffeecup
Sample Output 3
0.00000000000000000
ff is a substring of S, and its filling rate is 0.
There is no substring with a filling rate greater than 0, so the answer is 0.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
英小文字と ? からなる文字列 T と、英小文字のみからなる文字列 U が与えられます。
T は、英小文字のみからなる文字列 S のちょうど 4 文字を ? で置き換えることで得られた文字列です。
S が U を連続部分文字列として含んでいた可能性があるかどうか判定してください。
制約
- T は長さ 4 以上 10 以下の英小文字と
?からなる文字列 - T にはちょうど 4 つの
?が含まれる - U は長さ 1 以上 |T| 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
T U
出力
S が U を部分文字列として含んでいた可能性があるならば Yes を、そうでないならば No を出力せよ。
入力例 1
tak??a?h? nashi
出力例 1
Yes
例えば、S が takanashi である場合、これは nashi を連続部分文字列として含みます。
入力例 2
??e??e snuke
出力例 2
No
? がどのような文字であっても、S は snuke を連続部分文字列として含むことがありません。
入力例 3
???? aoki
出力例 3
Yes
Score : 250 points
Problem Statement
You are given a string T consisting of lowercase English letters and ?, and a string U consisting of lowercase English letters.
The string T is obtained by taking some lowercase-only string S and replacing exactly four of its characters with ?.
Determine whether it is possible that the original string S contained U as a contiguous substring.
Constraints
- T is a string of length between 4 and 10, inclusive, consisting of lowercase letters and
?. - T contains exactly four occurrences of
?. - U is a string of length between 1 and |T|, inclusive, consisting of lowercase letters.
Input
The input is given from Standard Input in the following format:
T U
Output
Print Yes if it is possible that the original string S contained U as a contiguous substring; otherwise, print No.
Sample Input 1
tak??a?h? nashi
Sample Output 1
Yes
For example, if S is takanashi, it contains nashi as a contiguous substring.
Sample Input 2
??e??e snuke
Sample Output 2
No
No matter what characters replace the ?s in T, S cannot contain snuke as a contiguous substring.
Sample Input 3
???? aoki
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
長さ N の狭義単調増加列 A=(A _ 1,A _ 2,\ldots,A _ N) と、長さ M の狭義単調増加列 B=(B _ 1,B _ 2,\ldots,B _ M) が与えられます。 ここで、すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j が成り立っています。
長さ N+M の狭義単調増加列 C=(C _ 1,C _ 2,\ldots,C _ {N+M}) を、次の操作を行った結果得られる列として定めます。
- C を A と B を連結した列とする。厳密には、i=1,2,\ldots,N について C _ i=A _ i とし、i=N+1,N+2,\ldots,N+M について C _ i=B _ {i-N} とする。
- C を昇順にソートする。
A _ 1,A _ 2,\ldots,A _ N と B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるか求めてください。 より厳密には、まず i=1,2,\ldots,N について C _ k=A _ i を満たす k を順に求めたのち、j=1,2,\ldots,M について C _ k=B _ j を満たす k を順に求めてください。
制約
- 1\leq N,M\leq 10^5
- 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
- 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
- すべての i,j\ (1\leq i\leq N,1\leq j\leq M) について A _ i\neq B _ j
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A _ 1 A _ 2 \ldots A _ N B _ 1 B _ 2 \ldots B _ M
出力
答えを 2 行で出力せよ。
1 行目には A _ 1,A _ 2,\ldots,A _ N がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
2 行目には B _ 1,B _ 2,\ldots,B _ M がそれぞれ C では何番目にあるかを空白区切りで出力せよ。
入力例 1
4 3 3 14 15 92 6 53 58
出力例 1
1 3 4 7 2 5 6
C は (3,6,14,15,53,58,92) となります。 A=(3,14,15,92) の要素はそれぞれ 1,3,4,7 番目にあり、B=(6,53,58) の要素はそれぞれ 2,5,6 番目にあります。
入力例 2
4 4 1 2 3 4 100 200 300 400
出力例 2
1 2 3 4 5 6 7 8
入力例 3
8 12 3 4 10 15 17 18 22 30 5 7 11 13 14 16 19 21 23 24 27 28
出力例 3
1 2 5 9 11 12 15 20 3 4 6 7 8 10 13 14 16 17 18 19
Score : 300 points
Problem Statement
You are given strictly increasing sequences of length N and M: A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B _ 1,B _ 2,\ldots,B _ M). Here, A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
Let C=(C _ 1,C _ 2,\ldots,C _ {N+M}) be a strictly increasing sequence of length N+M that results from the following procedure.
- Let C be the concatenation of A and B. Formally, let C _ i=A _ i for i=1,2,\ldots,N, and C _ i=B _ {i-N} for i=N+1,N+2,\ldots,N+M.
- Sort C in ascending order.
For each of A _ 1,A _ 2,\ldots,A _ N, B _ 1,B _ 2,\ldots,B _ M, find its position in C. More formally, for each i=1,2,\ldots,N, find k such that C _ k=A _ i, and for each j=1,2,\ldots,M, find k such that C _ k=B _ j.
Constraints
- 1\leq N,M\leq 10^5
- 1\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
- 1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
- A _ i\neq B _ j for every i and j (1\leq i\leq N,1\leq j\leq M).
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A _ 1 A _ 2 \ldots A _ N B _ 1 B _ 2 \ldots B _ M
Output
Print the answer in two lines.
The first line should contain the positions of A _ 1,A _ 2,\ldots,A _ N in C, with spaces in between.
The second line should contain the positions of B _ 1,B _ 2,\ldots,B _ M in C, with spaces in between.
Sample Input 1
4 3 3 14 15 92 6 53 58
Sample Output 1
1 3 4 7 2 5 6
C will be (3,6,14,15,53,58,92). Here, the 1-st, 3-rd, 4-th, 7-th elements are from A=(3,14,15,92), and the 2-nd, 5-th, 6-th elements are from B=(6,53,58).
Sample Input 2
4 4 1 2 3 4 100 200 300 400
Sample Output 2
1 2 3 4 5 6 7 8
Sample Input 3
8 12 3 4 10 15 17 18 22 30 5 7 11 13 14 16 19 21 23 24 27 28
Sample Output 3
1 2 5 9 11 12 15 20 3 4 6 7 8 10 13 14 16 17 18 19
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
それぞれ N 個、M 個の正整数からなる 2 つの数列 A=(A_1,A_2, \ldots ,A_N) と B=(B_1, \ldots ,B_M) が与えられます。
それぞれの数列から 1 つずつ要素を選んだときの 2 つの値の差の最小値、すなわち、 \displaystyle \min_{ 1\leq i\leq N}\displaystyle\min_{1\leq j\leq M} \lvert A_i-B_j\rvert を求めてください。
制約
- 1 \leq N,M \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
出力
答えを出力せよ。
入力例 1
2 2 1 6 4 9
出力例 1
2
それぞれの数列から 1 つずつ要素を選んだときの 2 つの値の差としてあり得るのは、 \lvert 1-4\rvert=3 、 \lvert 1-9\rvert=8 、 \lvert 6-4\rvert=2 、 \lvert 6-9\rvert=3 の 4 つです。 この中で最小である 2 を出力します。
入力例 2
1 1 10 10
出力例 2
0
入力例 3
6 8 82 76 82 82 71 70 17 39 67 2 45 35 22 24
出力例 3
3
Score : 300 points
Problem Statement
You are given two sequences: A=(A_1,A_2, \ldots ,A_N) consisting of N positive integers, and B=(B_1, \ldots ,B_M) consisting of M positive integers.
Find the minimum difference of an element of A and an element of B, that is, \displaystyle \min_{ 1\leq i\leq N}\displaystyle\min_{1\leq j\leq M} \lvert A_i-B_j\rvert.
Constraints
- 1 \leq N,M \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
Output
Print the answer.
Sample Input 1
2 2 1 6 4 9
Sample Output 1
2
Here is the difference for each of the four pair of an element of A and an element of B: \lvert 1-4\rvert=3, \lvert 1-9\rvert=8, \lvert 6-4\rvert=2, and \lvert 6-9\rvert=3. We should print the minimum of these values, or 2.
Sample Input 2
1 1 10 10
Sample Output 2
0
Sample Input 3
6 8 82 76 82 82 71 70 17 39 67 2 45 35 22 24
Sample Output 3
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
1 周の長さが M である池があり、その周上に 1 つの小屋と N 人の人が立っています。
実数 x (0\leq x <M) について、小屋から時計回りに x だけ進んだところを地点 x と定義します。
i 番目の人は、 地点 A_i にいます。
複数の人が同じ場所に立っていることもあります。
また、N 以下の整数 C が与えられます。 i=0,1,\ldots,M-1 について、X_i を次のように定義します。
- 高橋君は地点 (i+0.5) からスタートして、時計回りに動き始める。
- 高橋君は出会った人数の合計が C 未満である限り(時計回りに)動き続け、C 以上になったら止まる。ここで、「地点 y にいる人と出会う」とは、高橋君が地点 y に到達することを指す。
- 高橋君が止まるまでに出会った人数を X_i とする。ここで、高橋君が止まった地点に複数の人がいる場合、そこにいた人はすべて出会った人として数えられ、特に X_i は C より大きくなる可能性がある。
i=0,1,\ldots,M-1 にわたる X_i の総和、すなわち \displaystyle\sum_{i=0}^{M-1} X_i を求めてください。
制約
- 1\leq N\leq 5\times 10^5
- 1\leq M\leq 10^{12}
- 0\leq A_i\leq M-1
- 1\leq C\leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M C A_1 A_2 \ldots A_N
出力
i=0,1,\ldots,M-1 にわたる X_i の総和を一行に出力せよ。
入力例 1
5 3 2 1 2 1 0 1
出力例 1
9
i=0 のとき、高橋君は地点 0.5 からスタートして時計回りに動きます。その後、次のようになります。
- 地点 1 で 1,3,5 番目の 3 人と出会い、今まで出会った人数の合計は 3 となる。これは C=2 以上であるため、高橋くんはそこで止まる。よって、X_0=3 である。
i=1 のとき、高橋君は地点 1.5 からスタートして時計回りに動きます。その後、次のようになります。
- 地点 2 で 2 番目の人と出会う。今まで出会った人数の合計は 1 であるため、動き続ける。
- 地点 0 で 4 番目の人と出会い、今まで出会った人数の合計は 2 となる。これは C=2 以上であるため、高橋くんはそこで止まる。よって、X_1=2 である。
i=2 のとき、高橋君は地点 2.5 からスタートして時計回りに動きます。その後、次のようになります。
- 地点 0 で 4 番目の人と会う。今まで出会った人数の合計は 1 であるため、動き続ける。
- 地点 1 で 1,3,5 番目の 3 人と会い、今まで出会った人数の合計は 4 となる。これは C=2 以上であるため、高橋くんはそこで止まる。よって、X_2=4 である。
よって、答えは X_0+X_1+X_2=3+2+4=9 となります。
入力例 2
1 1000000000000 1 1
出力例 2
1000000000000
高橋君はスタートする位置によらず、池の周りに立っている唯一の人である、地点 1 にいる人に出会った時に止まります。
よって、i によらず X_i=1 であり、答えは 10^{12} となります。
Score : 425 points
Problem Statement
There is a pond with a circumference of M, and on its shore stand one hut and N people.
For a real number x (0\leq x <M), define point x as the location that is x distance clockwise from the hut.
The i-th person is at point A_i.
Multiple people may be standing at the same location.
Additionally, an integer C not greater than N is given. For i=0,1,\ldots,M-1, define X_i as follows:
- Takahashi starts at point (i+0.5) and begins moving clockwise.
- Takahashi continues moving (clockwise) as long as the total number of people he has met is less than C, and stops when it becomes C or more. Here, "meeting a person at point y" means that Takahashi reaches point y.
- Let X_i be the number of people Takahashi met before stopping. Here, if there are multiple people at the point where Takahashi stopped, all the people there are counted as people he met, and particularly, X_i may be greater than C.
Find the sum of X_i over i=0,1,\ldots,M-1, that is, \displaystyle\sum_{i=0}^{M-1} X_i.
Constraints
- 1\leq N\leq 5\times 10^5
- 1\leq M\leq 10^{12}
- 0\leq A_i\leq M-1
- 1\leq C\leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M C A_1 A_2 \ldots A_N
Output
Print the sum of X_i over i=0,1,\ldots,M-1 on a single line.
Sample Input 1
5 3 2 1 2 1 0 1
Sample Output 1
9
When i=0, Takahashi starts at point 0.5 and moves clockwise. Then, the following happens:
- At point 1, he meets the 1st, 3rd, and 5th people, a total of three people, and the total number of people met so far is 3. This is not less than C=2, so Takahashi stops there. Therefore, X_0=3.
When i=1, Takahashi starts at point 1.5 and moves clockwise. Then, the following happens:
- At point 2, he meets the 2nd person. The total number of people met so far is 1, so he continues moving.
- At point 0, he meets the 4th person, and the total number of people met so far is 2. This is not less than C=2, so Takahashi stops there. Therefore, X_1=2.
When i=2, Takahashi starts at point 2.5 and moves clockwise. Then, the following happens:
- At point 0, he meets the 4th person. The total number of people met so far is 1, so he continues moving.
- At point 1, he meets the 1st, 3rd, and 5th people, a total of three people, and the total number of people met so far is 4. This is not less than C=2, so Takahashi stops there. Therefore, X_2=4.
Therefore, the answer is X_0+X_1+X_2=3+2+4=9.
Sample Input 2
1 1000000000000 1 1
Sample Output 2
1000000000000
Regardless of the starting position, Takahashi stops when he meets the only person standing around the pond, who is at point 1.
Therefore, X_i=1 regardless of i, and the answer is 10^{12}.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
1 以上 N-1 以下の整数からなる長さ M の数列 A=(A_1,A_2,\dots,A_M) が与えられます。 i=1,2,\dots,M について、以下の質問に答えてください。
- 数列 B=(B_1,B_2,\dots,B_N) がある。最初、各 j について B_j=j である。今から、k=1,2,\dots,i-1,i+1,\dots,M の順に以下の操作を行う
(すなわち、i を除いた 1 以上 M 以下の整数 k について、昇順に以下の操作を行う)。
- B_{A_k} と B_{A_k+1} の値を入れ替える。
- 全ての操作が終了した段階で、B_j=1 を満たす j の値を S_i と定義する。S_i を求めよ。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1 \leq A_i \leq N-1\ (1\leq i \leq M)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_M
出力
M 行出力せよ。 i\ (1\leq i \leq M) 行目には、S_i の値を整数として出力せよ。
入力例 1
5 4 1 2 3 2
出力例 1
1 3 2 4
i = 2 のとき、操作によって B は以下のように変化します。
- 最初、B = (1,2,3,4,5)
- k=1 として操作を行う。すなわち B_1 と B_2 の値を入れ替えて、B = (2,1,3,4,5)
- k=3 として操作を行う。すなわち B_3 と B_4 の値を入れ替えて、B = (2,1,4,3,5)
- k=4 として操作を行う。すなわち B_2 と B_3 の値を入れ替えて、B = (2,4,1,3,5)
全ての操作が終了した段階で B_3=1 であるため、S_2 = 3 です。
同様に、
- i=1 のとき:k=2,3,4 の順に操作を行うと B=(1,4,3,2,5) になるので、S_1=1
- i=3 のとき:k=1,2,4 の順に操作を行うと B=(2,1,3,4,5) になるので、S_3=2
- i=4 のとき:k=1,2,3 の順に操作を行うと B=(2,3,4,1,5) になるので、S_4=4
です。
入力例 2
3 3 2 2 2
出力例 2
1 1 1
入力例 3
10 10 1 1 1 9 4 4 2 1 3 3
出力例 3
2 2 2 3 3 3 1 3 4 4
Score : 500 points
Problem Statement
You are given a sequence of length M consisting of integers between 1 and N-1, inclusive: A=(A_1,A_2,\dots,A_M). Answer the following question for i=1, 2, \dots, M.
- There is a sequence B=(B_1,B_2,\dots,B_N). Initially, we have B_j=j for each j. Let us perform the following operation for k=1, 2, \dots, i-1, i+1, \dots, M in this order (in other words, for integers k between 1 and M except i in ascending order).
- Swap the values of B_{A_k} and B_{A_k+1}.
- After all the operations, let S_i be the value of j such that B_j=1. Find S_i.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1 \leq A_i \leq N-1\ (1\leq i \leq M)
- All values in the input 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 M lines. The i-th line (1\leq i \leq M) should contain the value S_i as an integer.
Sample Input 1
5 4 1 2 3 2
Sample Output 1
1 3 2 4
For i = 2, the operations change B as follows.
- Initially, B = (1,2,3,4,5).
- Perform the operation for k=1. That is, swap the values of B_1 and B_2, making B = (2,1,3,4,5).
- Perform the operation for k=3. That is, swap the values of B_3 and B_4, making B = (2,1,4,3,5).
- Perform the operation for k=4. That is, swap the values of B_2 and B_3, making B = (2,4,1,3,5).
After all the operations, we have B_3=1, so S_2 = 3.
Similarly, we have the following.
- For i=1: performing the operation for k=2,3,4 in this order makes B=(1,4,3,2,5), so S_1=1.
- For i=3: performing the operation for k=1,2,4 in this order makes B=(2,1,3,4,5), so S_3=2.
- For i=4: performing the operation for k=1,2,3 in this order makes B=(2,3,4,1,5), so S_4=4.
Sample Input 2
3 3 2 2 2
Sample Output 2
1 1 1
Sample Input 3
10 10 1 1 1 9 4 4 2 1 3 3
Sample Output 3
2 2 2 3 3 3 1 3 4 4
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
部屋 1, 部屋 2, \ldots, 部屋 N と番号づけられた N 個の部屋に人が 1 人ずつ住んでおり、 また、いくつかの相異なる 2 つの部屋の間は通路によって結ばれています。 通路は M 本あり、i 本目の通路は部屋 U_i と部屋 V_i を結んでおり、長さは W_i です。
ある日(これを 0 日目とします)の夜に、部屋 A_1,A_2,\ldots, A_K に住んでいる K 人がウイルスに(新しく)感染してしまいました。 さらにその後の D 日間で i 日目 (1\leq i\leq D) には次のように感染が広がりました。
(i-1) 日目の夜の時点で感染していた人は、i 日目の夜の時点でも感染していた。
そうでない人については、(i-1) 日目の夜の時点で感染していた人の住んでいる部屋のうちの少なくとも 1 つから 距離 X_i 以内の部屋に住んでいた時かつその時に限り、新しく感染した。 ここで、部屋 P,Q の間の距離は、部屋 P から 部屋 Q まで通路のみを使って移動する時に通る通路の長さの総和としてあり得る最小値として定義される。 ただし、部屋 P から 部屋 Q へ通路のみを使って移動する事ができない時、距離は 10^{100} とする。
各 i (1\leq i\leq N) について、部屋 i に住んでいる人がそれぞれ何日目の夜に(新しく)感染したか出力してください。ただし、D 日目の夜の時点で感染していない場合は -1 を出力してください。
制約
- 1 \leq N\leq 3\times 10^5
- 0 \leq M\leq 3\times 10^5
- 1 \leq U_i < V_i\leq N
- (U_i,V_i) はすべて異なる。
- 1\leq W_i\leq 10^9
- 1 \leq K\leq N
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1 \leq D\leq 3\times 10^5
- 1\leq X_i\leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M U_1 V_1 W_1 U_2 V_2 W_2 \vdots U_M V_M W_M K A_1 A_2 \ldots A_K D X_1 X_2 \ldots X_D
出力
N 行出力せよ。
i 行目 (1\leq i\leq N) には、部屋 i に住んでいる人が何日目の夜に(新しく)感染したか出力せよ。
入力例 1
4 4 1 2 2 2 3 1 2 4 3 3 4 2 1 1 2 3 3
出力例 1
0 1 1 2
次のように感染は広がります。
- 0 日目の夜、部屋 1 に住んでいる人が感染する。
- 部屋 1 と部屋 2,3,4 の間の距離はそれぞれ 2,3,5 である。よって、X_1=3 であるから、1 日目の夜、部屋 2,3 に住んでいる人が新しく感染する。
- 部屋 3 と部屋 4 の間の距離は 2 である。よって、X_2=3 であるから、2 日目の夜、部屋 4 に住んでいる人も感染する。
よって、部屋 1,2,3,4 に住んでいる人はそれぞれ 0,1,1,2 日目に新しく感染したため、0,1,1,2 をこの順で各行に出力します。
入力例 2
7 7 1 2 2 2 3 3 3 4 1 4 5 1 5 6 3 3 7 1 4 7 1 2 1 6 2 2 3
出力例 2
0 1 2 -1 2 0 -1
入力例 3
5 1 1 2 5 2 1 3 3 3 7 5
出力例 3
0 2 0 -1 -1
どの 2 つの部屋の間も通路のみを使って移動できるとは限らないことに注意してください。
Score : 550 points
Problem Statement
There are N rooms numbered 1, 2, \ldots, N, each with one person living in it, and M corridors connecting two different rooms. The i-th corridor connects room U_i and room V_i with a length of W_i.
One day (we call this day 0), the K people living in rooms A_1, A_2, \ldots, A_K got (newly) infected with a virus. Furthermore, on the i-th of the following D days (1\leq i\leq D), the infection spread as follows.
People who were infected at the end of the night of day (i-1) remained infected at the end of the night of day i.
For those who were not infected, they were newly infected if and only if they were living in a room within a distance of X_i from at least one room where an infected person was living at the end of the night of day (i-1). Here, the distance between rooms P and Q is defined as the minimum possible sum of the lengths of the corridors when moving from room P to room Q using only corridors. If it is impossible to move from room P to room Q using only corridors, the distance is set to 10^{100}.
For each i (1\leq i\leq N), print the day on which the person living in room i was newly infected. If they were not infected by the end of the night of day D, print -1.
Constraints
- 1 \leq N\leq 3\times 10^5
- 0 \leq M\leq 3\times 10^5
- 1 \leq U_i < V_i\leq N
- All (U_i,V_i) are different.
- 1\leq W_i\leq 10^9
- 1 \leq K\leq N
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1 \leq D\leq 3\times 10^5
- 1\leq X_i\leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M U_1 V_1 W_1 U_2 V_2 W_2 \vdots U_M V_M W_M K A_1 A_2 \ldots A_K D X_1 X_2 \ldots X_D
Output
Print N lines.
The i-th line (1\leq i\leq N) should contain the day on which the person living in room i was newly infected.
Sample Input 1
4 4 1 2 2 2 3 1 2 4 3 3 4 2 1 1 2 3 3
Sample Output 1
0 1 1 2
The infection spreads as follows.
- On the night of day 0, the person living in room 1 gets infected.
- The distances between room 1 and rooms 2,3,4 are 2,3,5, respectively. Thus, since X_1=3, the people living in rooms 2 and 3 are newly infected on the night of day 1.
- The distance between rooms 3 and 4 is 2. Thus, since X_2=3, the person living in room 4 also gets infected on the night of day 2.
Therefore, the people living in rooms 1,2,3,4 were newly infected on days 0,1,1,2, respectively, so print 0,1,1,2 in this order on separate lines.
Sample Input 2
7 7 1 2 2 2 3 3 3 4 1 4 5 1 5 6 3 3 7 1 4 7 1 2 1 6 2 2 3
Sample Output 2
0 1 2 -1 2 0 -1
Sample Input 3
5 1 1 2 5 2 1 3 3 3 7 5
Sample Output 3
0 2 0 -1 -1
Note that it is not always possible to move between any two rooms using only corridors.