#P15732. [JAG 2024 Summer Camp #2] Do Make Segment Tree

    ID: 15640 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024ICPC斜率维护技巧 slope trick闵可夫斯基和 Minkowski sum

[JAG 2024 Summer Camp #2] Do Make Segment Tree

题目描述

Given an integer sequence B=(B1,B2,,B2N1)B = (B_1, B_2, \ldots, B_{2^N - 1}) of length 2N12^N - 1, define f(B)f(B) as follows:

  • f(B)f(B) is the minimum number of operations required to make the following condition true:
    • Operation: Choose one integer ii such that 1i2N11 \leq i \leq 2^N - 1, and either increase BiB_i by 11 or decrease BiB_i by 11.
    • Condition: For all ii where 1i2N111 \leq i \leq 2^{N-1} - 1, the condition Bi=B2i+B2i+1B_i = B_{2i} + B_{2i+1} should be satisfied.

You are given a sequence A=(A1,A2,,A2N1)A = (A_1, A_2, \ldots, A_{2^N - 1}) of length 2N12^N - 1.

Process QQ queries. For each query ii (where 1iQ1 \leq i \leq Q):

  • Given integers xix_i and viv_i, update AxiA_{x_i} to viv_i and then output f(A)f(A).

输入格式

The input is given in the following format:

$$\begin{aligned} &N \\ &A_1 \ A_2 \ \ldots \ A_{2^N - 1} \\ &Q \\ &x_1 \ v_1 \\ &x_2 \ v_2 \\ &\vdots \\ &x_Q \ v_Q \end{aligned} $$
  • 2N182 \leq N \leq 18
  • 1Q100,0001 \leq Q \leq 100,000
  • 109Ai109-10^9 \leq A_i \leq 10^9
  • 1xi2N11 \leq x_i \leq 2^N - 1
  • 109vi109-10^9 \leq v_i \leq 10^9
  • All input values are integers.

输出格式

Output QQ lines. On the ii-th line, output the answer for the ii-th query.

3
2 3 0 1 -5 2 1
5
3 1
5 3
6 -1
5 1
1 0
9
5
3
2
4