AT_ndpc2026_g.Mouth
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer sequence A=(A1,A2,…,AN) of length N.
Process Q queries. In each query, you are given an integer i (1≤i≤N) and a non-negative integer v. Update Ai to v, and then solve the following problem. (The updates are permanent.)
There are N people standing on a number line at positions 1 to N, each with their mouth open. Person i is at position i. Each person has a parameter called hunger, and the hunger of person i is Ai.
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 x such that 1≤x≤N, and stand at position x.
- Then, perform the following operations any number of times (possibly zero):
- Let your current position be y. Move to position y−1, y, or y+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 Bi be the number of candies given to person i. Find the minimum possible value of i=1∑N∣Ai−Bi∣.
给你一个长度为 N 的整数序列 A=(A1,A2,…,AN)。
你需要处理 Q 个查询。在每个查询中,你将收到一个整数 i(满足 1≤i≤N)和一个非负整数 v。请将 Ai 更新为 v,然后求解如下问题。(这些更新是永久性的。)
数轴上有 N 个人,分别站在位置 1 到 N 上,且每个人张着嘴。第 i 个人位于位置 i。每个人有一个称为饥饿值的参数,其中第 i 个人的饥饿值为 Ai。
你拥有无限数量的糖果。你决定恰好执行以下一系列操作一次,以喂饱他们:
- 首先,选择一个整数 x(满足 1≤x≤N),并站在位置 x。
- 然后,重复执行以下操作任意次数(可以为零次):
- 设你当前所在位置为 y。你可以移动到位置 y−1、y 或 y+1。但你不能移动到没有人的位置。
- 向你当前位置上的人投掷一颗糖果。
在完成所有操作后,设 Bi 表示分发给第 i 个人的糖果数量。求 i=1∑N∣Ai−Bi∣ 的最小可能值。
输入格式
The input is given from standard input in the following format:
N Q
A1 A2 … AN
query1
query2
⋮
queryQ
Each query is given in the following format:
i v
输入从标准输入中按以下格式给出:
N Q
A1 A2 … AN
query1
query2
⋮
queryQ
每个查询按以下格式给出:
i v
输出格式
Print Q lines. For the i-th line, output the answer to the i-th query.
输出 Q 行。对于第 i 行,输出第 i 个查询的答案。
输入输出样例
输入#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≤10, you will get 2 points.
Sample 1 Explanation:
Consider processing the first query. You need to solve the problem for A=(1,0,0,2).
In this case, the following actions achieve a value of 1, which is optimal:
- Choose x=3 and stand at position 3.
- Move to position 4 and give one candy to person 4.
- Stay at position 4 again and give another candy to person 4.
- End the operations. The resulting B becomes (0,0,0,2).
Constraints
- 1≤N≤105
- 1≤Q≤105
- 0≤Ai≤109
- 1≤i≤N
- 0≤v≤109
- All input values are integers
部分得分
本题采用部分得分制。
- 若你解决了满足 Q≤10 的数据集,则可获得 2 分。
样例 1 解释:
考虑处理第一个查询。此时需针对 A=(1,0,0,2) 求解。
在此情况下,以下操作可达到最优值 1:
- 选择 x=3,并站在位置 3;
- 移动到位置 4,并向第 4 个人给予一颗糖果;
- 再次停留在位置 4,并向第 4 个人再给予一颗糖果;
- 结束操作。最终得到的 B 为 (0,0,0,2)。
约束条件
- 1≤N≤105
- 1≤Q≤105
- 0≤Ai≤109
- 1≤i≤N
- 0≤v≤109
- 所有输入值均为整数
输入解题思路,AI测评打分。不知道怎么写?