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

19505번 - Process with Constant Sum 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB55311947.500%

문제

Suppose we have an array $a$ whose elements are non-negative integers. We can apply operations of two types to this array:

  1. $a_{i} \gets a_{i} - 2,ドル $a_{i+1} \gets a_{i+1} + 2$.
  2. If $a_{i+1} = 0$: $a_{i} \gets a_{i} - 1,ドル $a_{i+2} \gets a_{i+2} + 1$.

After any operation, all the elements must remain non-negative.

It is easy to see that we cannot do such operations indefinitely. We'll call a chain of operations maximal if no valid operation can occur after performing this chain of operations.

Now you are given an array $b$ of length $n$. Your should handle two types of queries:

  • "1 $p$ $x$" --- assignment $b_{p} \gets x$.
  • "2 $l$ $r$" --- let us treat the subsegment $b[l..r]$ as array $a$. You have to find the maximum number of zeroes which can be in that array after applying some maximal chain of operations. Note that we don't really change the array $b$ during this query.

입력

The first line of input contains one integer $n,ドル the length of array $b$ (1ドル \le n \le 2 \cdot 10^{5}$).

The second line contains $n$ integers separated by spaces: the initial elements of array $b$ (0ドル \le b_{i} \le 10^{5}$).

The third line contains one integer $q,ドル the number of queries (1ドル \le q \le 2 \cdot 10^{5}$).

Each of the next $q$ lines contains a query.

For queries of the first type, 1ドル \le p \le n$ and 0ドル \le x \le 10^{5}$.

For queries of the second type, 1ドル \le l \le r \le n$.

출력

For each query of the second type, print the answer on a separate line. Answers should be printed in the same order as queries.

제한

예제 입력 1

3
2 2 2
9
2 1 3
1 1 1
2 1 3
1 2 1
2 1 3
1 1 4
2 1 3
2 1 2
2 2 3

예제 출력 1

2
2
0
1
1
0

예제 입력 2

1
20500
1
2 1 1

예제 출력 2

0

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2016 > Day 7: Ural FU Dandelion Contest K번

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

출처

대학교 대회

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

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