#P15732. [JAG 2024 Summer Camp #2] Do Make Segment Tree
[JAG 2024 Summer Camp #2] Do Make Segment Tree
题目描述
Given an integer sequence of length , define as follows:
- is the minimum number of operations required to make the following condition true:
- Operation: Choose one integer such that , and either increase by or decrease by .
- Condition: For all where , the condition should be satisfied.
You are given a sequence of length .
Process queries. For each query (where ):
- Given integers and , update to and then output .
输入格式
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} $$- All input values are integers.
输出格式
Output lines. On the -th line, output the answer for the -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