Logo
(追記) (追記ここまで)

33021번 - Great City Saint Petersburg 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 2048 MB43191744.737%

문제

Saint Petersburg is the most beautiful city in the world unless it is raining. For the sake of this problem, we will assume it is raining every single day.

One of the streets in Saint Petersburg has an unusual shape --- it is a narrow stripe of $n$ sections 1ドル$ meter long each, where section $i$ is at the height $a_i$ meters from the ground. The stripe is 1ドル$ meter deep and bounded on the front and on the back by incredibly high buildings. Because of this, when it is raining, a certain amount of rain will accumulate, unable to flow out of the street from either its leftmost or rightmost end. Given the heights $a_1,ドル $a_2,ドル \ldots, $a_n,ドル you need to determine the amount of rain (in cubic meters) which will accumulate on the street.

Moreover, your colleagues from the metropolitan construction company will be visiting for $q$ days and on day $i$ they will be laying asphalt on all sections from $l_i$ to $r_i$ inclusive, thus increasing the height of each section $l_i,ドル $l_i+1,ドル \ldots, $r_i$ by 1ドル$ meter. You need to determine the total amount of water which accumulates on the street before the construction works, and also after every single day of the construction works.

입력

The first line contains the number of blocks $n$ and the number of construction events $q$ (1ドル \le n, q \le 2 \cdot 10^5$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ (1ドル \le a_i \le 10^9$) --- the height of each section before all the events. Each of the following $q$ lines contains a pair of integers $l_i,ドル $r_i$ (1ドル \le l_i \le r_i \le n$), denoting the construction work from $l_i$ to $r_i$ inclusive.

출력

Print $q+1$ integers --- the amount of water on the street before all updates, and also after every update.

제한

예제 입력 1

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

예제 출력 1

4
4
1
1
3

예제 입력 2

7 3
1 1000000000 1 1 1 1000000000 1
1 3
4 5
5 7

예제 출력 2

2999999997
2999999996
2999999994
2999999996

노트

The picture illustrates the amount of water accumulating on the street in the first example.

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2023 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /