CF995D.Game

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Allen and Bessie are playing a simple number game. They both know a function f:0,1n→Rf: {0, 1}^n \to \mathbb{R}, i. e. the function takes nn binary arguments and returns a real value. At the start of the game, the variables x1,x2,…,xnx_1, x_2, \dots, x_n are all set to −1-1. Each round, with equal probability, one of Allen or Bessie gets to make a move. A move consists of picking an ii such that xi=−1x_i = -1 and either setting xi→0x_i \to 0 or xi→1x_i \to 1.

After nn rounds all variables are set, and the game value resolves to f(x1,x2,…,xn)f(x_1, x_2, \dots, x_n). Allen wants to maximize the game value, and Bessie wants to minimize it.

Your goal is to help Allen and Bessie find the expected game value! They will play r+1r+1 times though, so between each game, exactly one value of ff changes. In other words, between rounds ii and i+1i+1 for 1≤i≤r1 \le i \le r, f(z1,…,zn)→gif(z_1, \dots, z_n) \to g_i for some (z1,…,zn)∈0,1n(z_1, \dots, z_n) \in {0, 1}^n. You are to find the expected game value in the beginning and after each change.

艾伦和贝西正在玩一个简单的数字游戏。他们都知道一个函数 f:0,1n→Rf: {0, 1}^n \to \mathbb{R},即该函数接收 nn 个二进制输入,并返回一个实数值。游戏开始时,变量 x1,x2,…,xnx_1, x_2, \dots, x_n 均被设为 −1-1。每一轮中,艾伦和贝西以相等的概率之一获得行动权。一次行动包括:选择一个满足 xi=−1x_i = -1 的下标 ii,并将 xix_i 设为 00 或 11。

经过 nn 轮后,所有变量均被赋值,游戏结果即为 f(x1,x2,…,xn)f(x_1, x_2, \dots, x_n)。艾伦希望最大化游戏结果,而贝西希望最小化它。

你的目标是帮助艾伦和贝西求出游戏的期望结果!不过,他们将共进行 r+1r+1 局游戏;而在每两局之间,函数 ff 恰好有一个取值发生改变。换言之,在第 ii 局与第 i+1i+1 局之间(其中 1≤i≤r1 \le i \le r),存在某个 (z1,…,zn)∈0,1n(z_1, \dots, z_n) \in {0, 1}^n,使得 f(z1,…,zn)f(z_1, \dots, z_n) 的值变为 gig_i。你需要依次求出初始状态以及每次修改后的期望游戏结果。

输入格式

The first line contains two integers nn and rr (1≤n≤181 \le n \le 18, 0≤r≤2180 \le r \le 2^{18}).

The next line contains 2n2^n integers c0,c1,…,c2n−1c_0, c_1, \dots, c_{2^n-1} (0≤ci≤1090 \le c_i \le 10^9), denoting the initial values of ff. More specifically, f(x0,x1,…,xn−1)=cxf(x_0, x_1, \dots, x_{n-1}) = c_x, if x=xn−1…x0‾x = \overline{x_{n-1} \ldots x_0} in binary.

Each of the next rr lines contains two integers zz and gg (0≤z≤2n−10 \le z \le 2^n - 1, 0≤g≤1090 \le g \le 10^9). If z=zn−1…z0‾z = \overline{z_{n-1} \dots z_0} in binary, then this means to set f(z0,…,zn−1)→gf(z_0, \dots, z_{n-1}) \to g.

第一行包含两个整数 nn 和 rr(1≤n≤181 \le n \le 18,0≤r≤2180 \le r \le 2^{18})。

第二行包含 2n2^n 个整数 c0,c1,…,c2n−1c_0, c_1, \dots, c_{2^n-1}(0≤ci≤1090 \le c_i \le 10^9),表示函数 ff 的初始值。更具体地,若 x=xn−1…x0‾x = \overline{x_{n-1} \ldots x_0} 为其二进制表示,则 f(x0,x1,…,xn−1)=cxf(x_0, x_1, \dots, x_{n-1}) = c_x。

接下来的 rr 行中,每行包含两个整数 zz 和 gg(0≤z≤2n−10 \le z \le 2^n - 1,0≤g≤1090 \le g \le 10^9)。若 z=zn−1…z0‾z = \overline{z_{n-1} \dots z_0} 为其二进制表示,则该操作表示将 f(z0,…,zn−1)f(z_0, \dots, z_{n-1}) 的值更新为 gg。

输出格式

Print r+1r+1 lines, the ii-th of which denotes the value of the game ff during the ii-th round. Your answer must have absolute or relative error within 10−610^{-6}.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if ∣a−b∣max⁡(1,∣b∣)≤10−6\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}.

输出 r+1r+1 行,其中第 ii 行表示游戏 ff 在第 ii 轮的值。你的答案必须满足绝对误差或相对误差在 10−610^{-6} 以内。

形式化地,设你的答案为 aa,评测机的答案为 bb。若 ∣a−b∣max⁡(1,∣b∣)≤10−6\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6},则你的答案被视为正确。

输入输出样例

  • 输入#1

    2 2
    0 1 2 3
    2 5
    0 4

    输出#1

    1.500000
    2.250000
    3.250000
  • 输入#2

    1 0
    2 3

    输出#2

    2.500000
  • 输入#3

    2 0
    1 1 1 1

    输出#3

    1.000000

说明/提示

Consider the second test case. If Allen goes first, he will set x1→1x_1 \to 1, so the final value will be 33. If Bessie goes first, then she will set x1→0x_1 \to 0 so the final value will be 22. Thus the answer is 2.52.5.

In the third test case, the game value will always be 11 regardless of Allen and Bessie's play.

考虑第二个测试用例。如果 Allen 先手,他将设置 x1→1x_1 \to 1,因此最终值为 33;如果 Bessie 先手,则她将设置 x1→0x_1 \to 0,因此最终值为 22。因此答案为 2.52.5。

在第三个测试用例中,无论 Allen 和 Bessie 如何操作,游戏的值恒为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页