Ex - Rating Estimator Editorial /

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600600

問題文

あなたは NN 個のコンテストに参加します。コンテストが開催される順にコンテスト 11, コンテスト 22, \dots コンテスト NN と呼びます。
各コンテストに参加すると、コンテストごとに パフォーマンス という値が与えられます。コンテスト ii で与えられるパフォーマンスを PiP_i とします。
また、あなたは レーティング という値を持っています。レーティングはコンテストでのパフォーマンスによって変化する値です。コンテストに参加する前のレーティングの値は 00 で、コンテスト nn に出た後のレーティングの値は 1n(i=1nPi)\frac{1}{n} \left(\sum_{i=1}^n P_i \right) に変化します。
ただし、あなたのレーティングが一度 BB 以上 になると、それ以降はコンテストに参加してもレーティングは変動しなくなります。

あなたはコンテストに出る前に、それぞれのコンテストで得られるパフォーマンスを予測することにしました。はじめ、コンテスト ii のパフォーマンスの予測値を aia_i とします。クエリが QQ 個与えられるので入力される順にすべて処理してください。

各クエリでは 2 個の整数 c,xc, x が与えられます。あなたは、まずコンテスト cc のパフォーマンスの予測値を xx に変更します。(この変更は永続的です。) そして、あなたが NN 個のコンテスト全てで現在の予測値通りのパフォーマンスを得られた場合の、全てのコンテストに参加した後のレーティングの値を答えてください。

制約

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • 1B1091 \leq B \leq 10^9
  • 1Q1051 \leq Q \leq 10^5
  • 0ai1090 \leq a_i \leq 10^9
  • 1cN1 \leq c \leq N
  • 0x1090 \leq x \leq 10^9
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。ただし、ci,xic_i, x_iii 番目のクエリで与えられる c,xc, x を意味する。

NN BB QQ
a1a_1 a2a_2 \dots aNa_N
c1c_1 x1x_1
c2c_2 x2x_2
\vdots
cQc_Q xQx_Q

出力

QQ 行出力せよ。ii 行目には ii 番目のクエリに対する答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10910^{-9} 以下であれば正解として扱われる。


入力例 1Copy

Copy
5 6 7
5 1 9 3 8
4 9
2 10
1 0
3 0
3 30
5 100
1 100

出力例 1Copy

Copy
6.000000000000000
7.500000000000000
6.333333333333333
5.400000000000000
13.333333333333334
13.333333333333334
100.000000000000000

はじめ、(a1,a2,a3,a4,a5)=(5,1,9,3,8)(a_1, a_2, a_3, a_4, a_5) = (5, 1, 9, 3, 8) です。
1 番目のクエリによって a4a_499 に変更されて (a1,a2,a3,a4,a5)=(5,1,9,9,8)(a_1, a_2, a_3, a_4, a_5) = (5, 1, 9, 9, 8) となります。
このとき、コンテスト ii でパフォーマンス aia_i を取った場合のあなたのレーティングの推移は次の通りです。

  • はじめ、レーティングは 00 です。
  • コンテスト 11 が終了した時点でレーティングは 5/1=55 / 1 = 5 に変化します。
  • コンテスト 22 が終了した時点でレーティングは (5+1)/2=3(5 + 1) / 2 = 3 に変化します。
  • コンテスト 33 が終了した時点でレーティングは (5+1+9)/3=5(5 + 1 + 9) / 3 = 5 に変化します。
  • コンテスト 44 が終了した時点でレーティングは (5+1+9+9)/4=6(5 + 1 + 9 + 9) / 4 = 6 に変化します。
  • 以降、レーティングの値は変化しません。なぜならば、44 番目のコンテストが終了した時点でレーティングが BB 以上の値になっているからです。

よって、全てのコンテストが終了した時点でのレーティングは 66 なので、1 行目にはこれを出力します。

Score : 600600 points

Problem Statement

You will participate in NN contests, numbered 11 to NN in chronological order.
A participant in each contest will be given a value called performance for that contest. Let PiP_i be the performance for contest ii.
Additionally, you have a value called rating, which changes according to the performances in contests. The initial rating is 00, and the rating after contest nn is 1n(i=1nPi)\frac{1}{n} \left(\sum_{i=1}^n P_i \right).
However, once your rating is BB or higher, later contests will not affect your rating.

Before the contests, you have decided to estimate your performance in each contest. Let aia_i be the initial estimate of your performance in contest ii. Process QQ queries in the order they are given.

In each query, you are given two integers cc and xx. First, change the estimate of your performance in contest cc to xx. (This change is persistent.) Then, assuming that you get the estimated performances in all NN contests, print your final rating after the contests.

Constraints

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • 1B1091 \leq B \leq 10^9
  • 1Q1051 \leq Q \leq 10^5
  • 0ai1090 \leq a_i \leq 10^9
  • 1cN1 \leq c \leq N
  • 0x1090 \leq x \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where cic_i and xix_i are the cc and xx for the ii-th query:

NN BB QQ
a1a_1 a2a_2 \dots aNa_N
c1c_1 x1x_1
c2c_2 x2x_2
\vdots
cQc_Q xQx_Q

Output

Print QQ lines. The ii-th line should contain the answer to the ii-th query.
Your output is considered correct if the absolute or relative error from the true answer is at most 10910^{-9}.


Sample Input 1Copy

Copy
5 6 7
5 1 9 3 8
4 9
2 10
1 0
3 0
3 30
5 100
1 100

Sample Output 1Copy

Copy
6.000000000000000
7.500000000000000
6.333333333333333
5.400000000000000
13.333333333333334
13.333333333333334
100.000000000000000

Initially, (a1,a2,a3,a4,a5)=(5,1,9,3,8)(a_1, a_2, a_3, a_4, a_5) = (5, 1, 9, 3, 8).
The first query changes a4a_4 to 99, making (a1,a2,a3,a4,a5)=(5,1,9,9,8)(a_1, a_2, a_3, a_4, a_5) = (5, 1, 9, 9, 8).
Here, assuming that your performance in contest ii is aia_i, your rating will change as follows.

  • Initially, your rating is 00.
  • After contest 11, your rating will be 5/1=55 / 1 = 5.
  • After contest 22, your rating will be (5+1)/2=3(5 + 1) / 2 = 3.
  • After contest 33, your rating will be (5+1+9)/3=5(5 + 1 + 9) / 3 = 5.
  • After contest 44, your rating will be (5+1+9+9)/4=6(5 + 1 + 9 + 9) / 4 = 6.
  • Your rating will no longer change, because your rating after contest 44 is not less than BB.

Thus, your final rating after the contests is 66, which should be printed in the first line.



2025-03-29 (Sat)
06:35:15 +00:00