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

28322번 - Triangle Collection 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB148857.143%

문제

Alice has a collection of sticks. Initially, she has $c_{\ell}$ sticks of length $\ell$ for each $\ell = 1, \ldots, N$.

Alice would like to use her sticks to make some isosceles triangles. An isosceles triangle is made of two sticks of the same length, say $\ell,ドル and a third stick with a length between 1ドル$ and 2ドル\ell - 1$ inclusive. Note that the triangles must strictly obey the triangle inequality, and equilateral triangles are okay. Each stick may be used in at most one triangle. Alice would like to know the maximum number of isosceles triangles she can make with her sticks.

There are $Q$ events that change the collection of sticks she has. The $i$-th event consists of two integers $\ell_{i}$ and $d_i,ドル representing that the number of sticks of length $\ell_{i}$ changes by $d_{i}$. Note that $d_i$ may be positive, negative, or even 0ドル,ドル but Alice will never have a negative number or more than 10ドル^9$ sticks of each length.

Your task is to determine the maximum number of isosceles triangles Alice can make after each event if she uses her sticks optimally.

입력

The first line of input contains two space-separated integers $N$ and $Q$.

The second line of input contains $N$ space-separated integers $c_1, c_2,\ldots, c_N$ $(0 \le c_i \le 10^9),ドル representing Alice's initial collection.

The next $Q$ lines of input each contain two space-separated integers $\ell_i$ and $d_i$ $(1 \le \ell_i \le N, -10^9 \le d_i \le 10^9),ドル representing an event.

Initially and after each event, the number of sticks of length $\ell$ is between 0ドル$ and 10ドル^9$ for all $\ell = 1,\ldots, N$.

출력

Output $Q$ lines each containing a single integer, the answer after each event.

제한

  • 1ドル \le N,Q \le 200,000円$

예제 입력 1

4 3
3 1 4 1
3 -3
1 6
2 1

예제 출력 1

1
3
4

After the first event, Alice can make a single triangle with sticks of lengths $(1, 1, 1)$.

After the second event, Alice can make 3ドル$ triangles with sticks of lengths $(1, 1, 1)$.

After the third event, Alice can make 3ドル$ triangles with sticks of lengths $(1, 1, 1)$ and a triangle with sticks of lengths $(2, 2, 3)$.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCO 2023 6번

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

출처

대학교 대회

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

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