logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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:

  • All input values are integers.

输出格式

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

样例

样例输入 1

3
2 3 0 1 -5 2 1
5
3 1
5 3
6 -1
5 1
1 0

样例输出 1

9
5
3
2
4