CF1316F.Battalion Strength

普及/提高-

通过率:0%

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 a1a2aka_1 \le a_2 \le \dots \le a_k . The strength of this battalion is equal to a1a2+a2a3++ak1aka_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≢0modMq\not\equiv 0 \bmod M ). Output the integer equal to pq1modMp\cdot q^{-1} \bmod M . In other words, output such an integer xx that 0x<M0 \leq x < M and xqpmodMx ⋅ q \equiv p \bmod M ).

输入格式

The first line of the input contains a single integer nn ( 1n31051 \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} ( 1pi1091 \leq p_{i} \leq 10^{9} ).

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

Each of the next qq lines contains two integers ii and xx ( 1in1 \leq i \leq n , $ 1 \leq x \leq 10^{9}$ ), indicating that pip_{i} is updated to 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.

输入输出样例

  • 输入#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} .

首页