C - Decrease 2 max elements

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の正整数列 A = (A_1, A_2, \dots ,A_N) が与えられます。高橋くんは、以下の操作を A に含まれる正の要素の個数が 1 つ以下になるまで繰り返します。

  • A を要素の降順に並び替える。それから、 A_1, A_21 減らす。

高橋くんが操作をする回数を求めてください。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 100
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \cdots A_N

出力

答えを出力せよ。


入力例 1

4
1 2 3 3

出力例 1

4

操作は以下のように進みます。

  • 1 回目の操作で A = (2, 2, 2, 1) となる。
  • 2 回目の操作で A = (1, 1, 2, 1) となる。
  • 3 回目の操作で A = (1, 0, 1, 1) となる。
  • 4 回目の操作で A = (0, 0, 1, 0) となる。A に含まれる正の要素の個数が 1 つ以下になったので、ここで操作を終了する。

入力例 2

3
1 1 100

出力例 2

2

Score : 200 points

Problem Statement

You are given a sequence of N positive integers A = (A_1, A_2, \dots ,A_N). Takahashi repeats the following operation until A contains one or fewer positive elements:

  • Sort A in descending order. Then, decrease both A_1 and A_2 by 1.

Find the number of times he performs this operation.

Constraints

  • 2 \leq N \leq 100
  • 1 \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 \cdots A_N

Output

Print the answer.


Sample Input 1

4
1 2 3 3

Sample Output 1

4

The process goes as follows:

  • After the 1st operation, A is (2, 2, 2, 1).
  • After the 2nd operation, A is (1, 1, 2, 1).
  • After the 3rd operation, A is (1, 0, 1, 1).
  • After the 4th operation, A is (0, 0, 1, 0). A no longer contains more than one positive elements, so the process ends here.

Sample Input 2

3
1 1 100

Sample Output 2

2
D - Yellow and Red Card

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

1 から N までの番号がついた N 人の選手がサッカーの試合をします。
選手が反則を犯したとき、その選手には イエローカードレッドカード のどちらかが提示されます。
以下の条件のうち一方を満たした選手は 退場処分 と呼ばれるペナルティを受けます。

  • イエローカードを累計 2 回提示される。
  • レッドカードを提示される。

なお、退場処分を受けた選手にそれ以降カードが提示されることはありません。

あなたはこの試合を観戦します。はじめ、すべての選手はカードを 1 回も提示されていません。
Q 個のイベントが発生するので、イベントで聞かれる質問に正しく答えてください。
イベントは 3 種類あり、c x (c1, 2, 3 のいずれか) という形式で入力から与えられます。イベントの説明は次の通りです。

  • 1 x : 選手 x にイエローカードが提示される。
  • 2 x : 選手 x にレッドカードが提示される。
  • 3 x : あなたは選手 x が退場処分を受けたかを質問される。選手 x が退場処分を受けていれば Yes と、そうでなければ No と答える。

制約

  • 1 \leq N \leq 100
  • 1 \leq Q \leq 100
  • 全てのイベントにおいて 1 \leq x \leq N
  • 3 種類目のイベントは少なくとも 1 個以上存在する
  • すでに退場処分を受けた選手にカードが提示されることはない
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。ただし、\text{event}_ii 番目に発生するイベントを意味する。

N Q
\text{event}_1
\text{event}_2
\vdots
\text{event}_Q

イベントは次の 3 つのいずれかの形式で入力される。

1 x
2 x
3 x

出力

入力で与えられる 3 種類目のイベントの個数を X として、X 行出力せよ。
i 行目には、3 種類目のイベントのうち i 番目のもので聞かれる質問について、選手 x が退場処分を受けていれば Yes を、そうでなければ No を出力せよ。


入力例 1

3 9
3 1
3 2
1 2
2 1
3 1
3 2
1 2
3 2
3 3

出力例 1

No
No
Yes
No
Yes
No

イベントを時系列順にすべて説明すると次の通りです。

1 番目のイベントでは、あなたは選手 1 が退場処分を受けたかを質問されます。選手 1 は退場処分を受けていないので No を出力します。
2 番目のイベントでは、あなたは選手 2 が退場処分を受けたかを質問されます。選手 2 は退場処分を受けていないので No を出力します。
3 番目のイベントでは、選手 2 にイエローカードが提示されます。
4 番目のイベントでは、選手 1 にレッドカードが提示されます。選手 1 は退場処分を受けます。
5 番目のイベントでは、あなたは選手 1 が退場処分を受けたかを質問されます。選手 1 は退場処分を受けたので Yes を出力します。
6 番目のイベントでは、あなたは選手 2 が退場処分を受けたかを質問されます。選手 2 は退場処分を受けていないので No を出力します。
7 番目のイベントでは、選手 2 にイエローカードが提示されます。選手 2 は退場処分を受けます。
8 番目のイベントでは、あなたは選手 2 が退場処分を受けたかを質問されます。選手 2 は退場処分を受けたので Yes を出力します。
9 番目のイベントでは、あなたは選手 3 が退場処分を受けたかを質問されます。選手 3 は退場処分を受けていないので No を出力します。

Score : 200 points

Problem Statement

N players numbered 1 to N will play a soccer game.
When a player commits an offense, that player will receive a yellow card or a red card.
A player who satisfies one of the following conditions will be removed from the game.

  • Accumulates two yellow cards.
  • Receives a red card.

Once a player is removed, that player will no longer receive any cards.

You will watch this game. Initially, the players have not received any cards.
There will be Q events. Correctly answer the questions asked in the events.
There are three kinds of events, which are given in the format c x from the input, where c is 1, 2, or 3. The events are as follows.

  • 1 x: Player x receives a yellow card.
  • 2 x: Player x receives a red card.
  • 3 x: You are asked whether player x has been removed from the game. Answer Yes or No.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq Q \leq 100
  • 1 \leq x \leq N in all events.
  • There is at least one event of the third kind.
  • A player who has been removed will no longer receive any cards.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where \text{event}_i denotes the i-th event.

N Q
\text{event}_1
\text{event}_2
\vdots
\text{event}_Q

Each event is in one of the following formats:

1 x
2 x
3 x

Output

Print X lines, where X is the number of events of the third kind in the input.
The i-th line should contain Yes if, for the i-th event of the third kind, player x has been removed from the game, and No otherwise.


Sample Input 1

3 9
3 1
3 2
1 2
2 1
3 1
3 2
1 2
3 2
3 3

Sample Output 1

No
No
Yes
No
Yes
No

Here are all the events in chronological order.

In the 1-st event, you are asked whether player 1 has been removed from the game. Player 1 has not been removed, so you should print No.
In the 2-nd event, you are asked whether player 2 has been removed from the game. Player 2 has not been removed, so you should print No.
In the 3-rd event, player 2 receives a yellow card.
In the 4-th event, player 1 receives a red card and is removed from the game.
In the 5-th event, you are asked whether player 1 has been removed from the game. Player 1 has been removed, so you should print Yes.
In the 6-th event, you are asked whether player 2 has been removed from the game. Player 2 has not been removed, so you should print No.
In the 7-th event, player 2 receives a yellow card and is removed from the game.
In the 8-th event, you are asked whether player 2 has been removed from the game. Player 2 has been removed, so you should print Yes.
In the 9-th event, you are asked whether player 3 has been removed from the game. Player 3 has not been removed, so you should print No.

E - Festival

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

AtCoder 王国では、これから N 日間のお祭りが開催されます。そのうち、A_1 日目、A_2 日目、\dotsA_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
F - Standings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

1 から N の番号が付いた N 人がコイントスを何回かしました。人 iA_i 回表を出し、B_i 回裏を出したこと分かっています。

i のコイントスの 成功率\displaystyle\frac{A_i}{A_i+B_i} で定義されます。人 1,\ldots,N の番号を、成功率の高い順に並び替えてください。成功率が同じ人が複数いる場合、その中では人の番号が小さい順になるように並び替えてください。

制約

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i, B_i\leq 10^9
  • A_i+B_i \geq 1
  • 入力される数値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 B_1
\vdots
A_N B_N

出力

1,\ldots,N の番号を成功率の高い順に空白区切りで出力せよ。成功率が同じ人の番号は昇順に並び替えて出力せよ。


入力例 1

3
1 3
3 1
2 2

出力例 1

2 3 1

1 の成功率は 0.25、人 2 の成功率は 0.75、人 3 の成功率は 0.5 です。

成功率の高い順に並び替えると出力例の順番になります。


入力例 2

2
1 3
2 6

出力例 2

1 2

1,2 は成功率が同じなので、番号の昇順に出力することに注意してください。


入力例 3

4
999999999 1000000000
333333333 999999999
1000000000 999999997
999999998 1000000000

出力例 3

3 1 4 2

Score : 300 points

Problem Statement

N people numbered 1 through N tossed a coin several times. We know that person i's tosses resulted in A_i heads and B_i tails.

Person i's success rate of the tosses is defined by \displaystyle\frac{A_i}{A_i+B_i}. Sort people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.

Constraints

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i, B_i\leq 10^9
  • A_i+B_i \geq 1
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1 B_1
\vdots
A_N B_N

Output

Print the numbers of people 1,\ldots,N in descending order of their success rates, with ties broken in ascending order of their assigned numbers.


Sample Input 1

3
1 3
3 1
2 2

Sample Output 1

2 3 1

Person 1's success rate is 0.25, person 2's is 0.75, and person 3's is 0.5.

Sort them in descending order of their success rates to obtain the order in Sample Output.


Sample Input 2

2
1 3
2 6

Sample Output 2

1 2

Note that person 1 and 2 should be printed in ascending order of their numbers, as they have the same success rates.


Sample Input 3

4
999999999 1000000000
333333333 999999999
1000000000 999999997
999999998 1000000000

Sample Output 3

3 1 4 2
G - 9 Divisors

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

N 以下の正整数のうち、正の約数をちょうど 9 個持つものの個数を求めてください。

制約

  • 1\leq N\leq 4\times 10^{12}
  • 入力される数値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N

出力

答えを出力せよ。


入力例 1

200

出力例 1

3

条件を満たす正整数は 36,100,1963 個です。


入力例 2

4000000000000

出力例 2

407073

Score : 400 points

Problem Statement

Find the number of positive integers not greater than N that have exactly 9 positive divisors.

Constraints

  • 1 \leq N \leq 4 \times 10^{12}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

200

Sample Output 1

3

Three positive integers 36,100,196 satisfy the condition.


Sample Input 2

4000000000000

Sample Output 2

407073