AT_ndpc2026_g.Mouth

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given an integer sequence A=(A1,A2,…,AN)A = (A_1, A_2, \dots, A_N) of length NN.
Process QQ queries. In each query, you are given an integer ii (1≤i≤N1 \leq i \leq N) and a non-negative integer vv. Update AiA_i to vv, and then solve the following problem. (The updates are permanent.)

There are NN people standing on a number line at positions 11 to NN, each with their mouth open. Person ii is at position ii. Each person has a parameter called hunger, and the hunger of person ii is AiA_i.
You have an unlimited number of candies. You decide to perform the following sequence of actions exactly once to feed them:

  • First, choose an integer xx such that 1≤x≤N1 \leq x \leq N, and stand at position xx.
  • Then, perform the following operations any number of times (possibly zero):
    • Let your current position be yy. Move to position y−1y-1, yy, or y+1y+1. However, you cannot move to a position where no person is standing.
    • Throw one candy into the mouth of the person at your current position.

After finishing all operations, let BiB_i be the number of candies given to person ii. Find the minimum possible value of ∑i=1N∣Ai−Bi∣\displaystyle \sum_{i=1}^N \vert A_i - B_i \vert.

给你一个长度为 NN 的整数序列 A=(A1,A2,…,AN)A = (A_1, A_2, \dots, A_N)。
你需要处理 QQ 个查询。在每个查询中,你将收到一个整数 ii(满足 1≤i≤N1 \leq i \leq N)和一个非负整数 vv。请将 AiA_i 更新为 vv,然后求解如下问题。(这些更新是永久性的。)

数轴上有 NN 个人,分别站在位置 11 到 NN 上,且每个人张着嘴。第 ii 个人位于位置 ii。每个人有一个称为饥饿值的参数,其中第 ii 个人的饥饿值为 AiA_i。
你拥有无限数量的糖果。你决定恰好执行以下一系列操作一次,以喂饱他们:

  • 首先,选择一个整数 xx(满足 1≤x≤N1 \leq x \leq N),并站在位置 xx。
  • 然后,重复执行以下操作任意次数(可以为零次):
    • 设你当前所在位置为 yy。你可以移动到位置 y−1y-1、yy 或 y+1y+1。但你不能移动到没有人的位置。
    • 向你当前位置上的人投掷一颗糖果。

在完成所有操作后,设 BiB_i 表示分发给第 ii 个人的糖果数量。求 ∑i=1N∣Ai−Bi∣\displaystyle \sum_{i=1}^N \vert A_i - B_i \vert 的最小可能值。

输入格式

The input is given from standard input in the following format:

NN QQ
A1A_1 A2A_2 …\dots ANA_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in the following format:

ii vv

输入从标准输入中按以下格式给出:

NN QQ
A1A_1 A2A_2 …\dots ANA_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询按以下格式给出:

ii vv

输出格式

Print QQ lines. For the ii-th line, output the answer to the ii-th query.

输出 QQ 行。对于第 ii 行,输出第 ii 个查询的答案。

输入输出样例

  • 输入#1

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

    输出#1

    1
    2
    1
  • 输入#2

    10 9
    1 0 0 0 0 0 4 0 0 2
    3 2
    7 0
    1 9
    6 4
    1 1
    10 0
    1 0
    6 0
    5 7

    输出#2

    5
    3
    3
    5
    5
    3
    2
    0
    1

说明/提示

Partial Score

This problem has partial scoring.

  • If you solve the dataset with Q≤10Q \leq 10, you will get 22 points.

Sample 1 Explanation:
Consider processing the first query. You need to solve the problem for A=(1,0,0,2)A = (1,0,0,2).
In this case, the following actions achieve a value of 11, which is optimal:

  • Choose x=3x=3 and stand at position 33.
  • Move to position 44 and give one candy to person 44.
  • Stay at position 44 again and give another candy to person 44.
  • End the operations. The resulting BB becomes (0,0,0,2)(0,0,0,2).

Constraints

  • 1≤N≤1051 \leq N \leq 10^5
  • 1≤Q≤1051 \leq Q \leq 10^5
  • 0≤Ai≤1090 \leq A_i \leq 10^9
  • 1≤i≤N1 \leq i \leq N
  • 0≤v≤1090 \leq v \leq 10^9
  • All input values are integers

部分得分

本题采用部分得分制。

  • 若你解决了满足 Q≤10Q \leq 10 的数据集,则可获得 22 分。

样例 1 解释:
考虑处理第一个查询。此时需针对 A=(1,0,0,2)A = (1,0,0,2) 求解。
在此情况下,以下操作可达到最优值 11:

  • 选择 x=3x=3,并站在位置 33;
  • 移动到位置 44,并向第 44 个人给予一颗糖果;
  • 再次停留在位置 44,并向第 44 个人再给予一颗糖果;
  • 结束操作。最终得到的 BB 为 (0,0,0,2)(0,0,0,2)。

约束条件

  • 1≤N≤1051 \leq N \leq 10^5
  • 1≤Q≤1051 \leq Q \leq 10^5
  • 0≤Ai≤1090 \leq A_i \leq 10^9
  • 1≤i≤N1 \leq i \leq N
  • 0≤v≤1090 \leq v \leq 10^9
  • 所有输入值均为整数

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

首页