QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 125 MB Total points: 100

#7491. 纵使日薄西山

统计

题目描述

珂朵莉想让你维护一个长度为 $n$ 的正整数序列 $a_1,a_2,\ldots,a_n$,支持修改序列中某个位置的值。

每次修改后问对序列重复进行以下操作,需要进行几次操作才能使序列变为全 $0$(询问后序列和询问前相同,不会变为全 $0$):

选出序列中最大值的出现位置,若有多个最大值则选位置标号最小的一个,设位置为 $x$,则将 $a_{x-1},a_x,a_{x+1}$ 的值减 $1$,如果序列中存在小于 $0$ 的数,则把对应的数改为 $0$。

输入格式

第一行一个整数 $n$。

接下来 $n$ 行,每行一个整数 $a_i$。

接下来一行一个整数 $q$。

接下来 $q$ 行,每行两个用空格分隔的整数 $x_i,y_i$,表示把 $a_{x_i}$ 修改为 $y_i$。

输出格式

$q$ 行,每行一个整数表示答案。

样例 #1

样例输入 #1

4
3
6
6
4
3
4 4
3 5
1 8

样例输出 #1

10
10
13

提示

Idea:ccz181078,Solution:ccz181078,Code:ccz181078,Data:ccz181078

$1\leq n,q\leq 10^5$,$1\leq x_i\leq n$,$1\leq a_i,y_i\leq 10^9$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.