CF1316F.Battalion Strength

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn officers in the Army of Byteland. Each officer has some power associated with him. The power of the ii-th officer is denoted by pip_{i}. As the war is fast approaching, the General would like to know the strength of the army.

The strength of an army is calculated in a strange way in Byteland. The General selects a random subset of officers from these nn officers and calls this subset a battalion.(All 2n2^n subsets of the nn officers can be chosen equally likely, including empty subset and the subset of all officers).

The strength of a battalion is calculated in the following way:

Let the powers of the chosen officers be a1,a2,…,aka_{1},a_{2},\ldots,a_{k}, where a1≤a2≤⋯≤aka_1 \le a_2 \le \dots \le a_k. The strength of this battalion is equal to a1a2+a2a3+⋯+ak−1aka_1a_2 + a_2a_3 + \dots + a_{k-1}a_k. (If the size of Battalion is ≤1\leq 1, then the strength of this battalion is 00).

The strength of the army is equal to the expected value of the strength of the battalion.

As the war is really long, the powers of officers may change. Precisely, there will be qq changes. Each one of the form ii xx indicating that pip_{i} is changed to xx.

You need to find the strength of the army initially and after each of these qq updates.

Note that the changes are permanent.

The strength should be found by modulo 109+710^{9}+7. Formally, let M=109+7M=10^{9}+7. It can be shown that the answer can be expressed as an irreducible fraction p/qp/q, where pp and qq are integers and q≢0 mod Mq\not\equiv 0 \bmod M). Output the integer equal to p⋅q−1 mod Mp\cdot q^{-1} \bmod M. In other words, output such an integer xx that 0≤x<M0 \leq x \lt M and x⋅q≡p mod Mx ⋅ q \equiv p \bmod M).

Byteland 军队中有 nn 名军官。每名军官都具有一定的力量值,第 ii 名军官的力量值记为 pip_{i}。由于战争即将爆发,将军希望了解军队的总体实力。

Byteland 军队的实力以一种特殊的方式计算。将军会从这 nn 名军官中随机选取一个子集,并称该子集为一个“营”(battalion)。(所有 2n2^n 个子集——包括空集以及包含全部 nn 名军官的子集——被选中的概率均相等。)

一个营的实力按如下方式计算:

设所选军官的力量值为 a1,a2,…,aka_{1},a_{2},\ldots,a_{k},且满足 a1≤a2≤⋯≤aka_1 \le a_2 \le \dots \le a_k。则该营的实力等于

a1a2+a2a3+⋯+ak−1ak.a_1a_2 + a_2a_3 + \dots + a_{k-1}a_k.

(若营的大小 ≤1\leq 1,则其实力定义为 00。)

军队的总体实力定义为:营的实力的期望值。

由于战争持续时间很长,军官的力量值可能会发生变化。具体而言,将发生 qq 次更新操作。每次更新形如 ii xx,表示将 pip_{i} 的值修改为 xx。

你需要计算:军队初始时的实力,以及每次更新操作后的实力。

注意:这些更新是永久生效的。

答案需对 109+710^{9}+7 取模。形式化地,令 M=109+7M = 10^{9}+7。可以证明,答案总可表示为既约分数 p/qp/q,其中 p,qp, q 为整数,且 q≢0(modM)q \not\equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,请输出唯一满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入格式

The first line of the input contains a single integer nn (1≤n≤3⋅1051 \leq n \leq 3⋅10^{5}) — the number of officers in Byteland's Army.

The second line contains nn integers p1,p2,…,pnp_{1},p_{2},\ldots,p_{n} (1≤pi≤1091 \leq p_{i} \leq 10^{9}).

The third line contains a single integer qq (1≤q≤3⋅1051 \leq q \leq 3⋅10^{5}) — the number of updates.

Each of the next qq lines contains two integers ii and xx (1≤i≤n1 \leq i \leq n, $ 1 \leq x \leq 10^{9}$), indicating that pip_{i} is updated to xx .

输入的第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3⋅10^{5})—— 表示比特兰军队中军官的数量。

第二行包含 nn 个整数 p1,p2,…,pnp_{1},p_{2},\ldots,p_{n}(1≤pi≤1091 \leq p_{i} \leq 10^{9})。

第三行包含一个整数 qq(1≤q≤3⋅1051 \leq q \leq 3⋅10^{5})—— 表示更新操作的次数。

接下来的 qq 行,每行包含两个整数 ii 和 xx(1≤i≤n1 \leq i \leq n, $ 1 \leq x \leq 10^{9}$),表示将 pip_{i} 更新为 xx。

输出格式

In the first line output the initial strength of the army.

In ii-th of the next qq lines, output the strength of the army after ii-th update.

在第一行输出军队的初始战力。

在接下来的 qq 行中,第 ii 行输出第 ii 次更新后军队的战力。

输入输出样例

  • 输入#1

    2
    1 2
    2
    1 2
    2 1

    输出#1

    500000004
    1
    500000004
  • 输入#2

    4
    1 2 3 4
    4
    1 5
    2 5
    3 5
    4 5

    输出#2

    625000011
    13
    62500020
    375000027
    62500027

说明/提示

In first testcase, initially, there are four possible battalions

  • {} Strength = 00
  • {11} Strength = 00
  • {22} Strength = 00
  • {1,21,2} Strength = 22

So strength of army is 0+0+0+24\frac{0+0+0+2}{4} = 12\frac{1}{2}

After changing p1p_{1} to 22, strength of battallion {1,21,2} changes to 44, so strength of army becomes 11.

After changing p2p_{2} to 11, strength of battalion {1,21,2} again becomes 22, so strength of army becomes 12\frac{1}{2}.

在第一个测试用例中,初始时存在四种可能的军团:

  • {} 强度 = 00
  • {11} 强度 = 00
  • {22} 强度 = 00
  • {1,21,2} 强度 = 22

因此,军队的强度为 0+0+0+24\frac{0+0+0+2}{4} = 12\frac{1}{2}。

将 p1p_{1} 修改为 22 后,军团 {1,21,2} 的强度变为 44,因此军队的强度变为 11。

将 p2p_{2} 修改为 11 后,军团 {1,21,2} 的强度再次变为 22,因此军队的强度变为 12\frac{1}{2}。

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

首页