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

문제

JOI-kun has $N$ fishes, numbered from $1$ to $N$. The size of the fish $i$ ($1 ≤ i ≤ N$) is $A_i$.

When we grow fish, we have to pay attention to the following fact: if we have two nearby fishes, one fish eats the other fish as time passes. Here, two fishes are nearby if there is no fish between them. More precisely, if the size of the fish $x$ is larger than or equal to the size of the fish $y$, and the fish $x$ and the fish $y$ are nearby, then the fish $x$ eats the fish $y$, and the size of $x$ becomes the sum of the original size of $x$ and the size of $y$. If the fish $x$ and the fish $y$ have the same size, any one of them may eat the other.

JOI-kun will grow fishes for $Q$ days. To kill time, he does the following thought experiment. On the $j$-th day ($1 ≤ j ≤ Q$), JOI-kun takes one of the following actions.

  • Type 1 : JOI-kun gives a special feed to the fish $X_j$. After that, the size of the fish $X_j$ becomes $Y_j$.
  • Type 2 : JOI-kun takes only the fishes whose indices are between $L_j$ and $R_j$, inclusive. Then JOI-kun performs the following thought experiment: JOI-kun puts the fishes $L_j$, $L_j + 1$, $\dots$, $R_j$ into an aquarium from left to right. By the above properties of the fishes, only one fish will survive in the aquarium. The index of the surviving fish depends on the choice of eaten fishes and the time when a fish eats another fish. JOI-kun wants to know the number of possible indices of surviving fishes. During the thought experiment, the order of the fishes does not change, and no two fishes eat the same fish simultaneously.

Write a program which, given information of JOI-kun’s fishes and JOI-kun’s plan, calculates the number of possible indices of surviving fishes for each action of Type 2 in order to determine whether JOI-kun’s thought is correct or not. Note that this is just a thought experiment. Please be assured that no fishes are eaten actually.

입력

Read the following data from the standard input. Given values are all integers.

$\begin{align*}& N \\ & A_1 \, A_2 \, \cdots \, A_N \\ & Q \\ & \text{(Query }1\text{)} \\ & \text{(Query }2\text{)} \\ & \vdots \\ & \text{(Query }Q\text{)}  \end{align*}$

Each $\text{(Query }j\text{)}$ ($1 ≤ j ≤ Q$) consists of space separated integers. Let $T_j$ be the first integer of $\text{(Query }j\text{)}$. The content of this line is one of the following.

  • If $T_j = 1$, this line contains two more space separated integers $X_j$, $Y_j$, in this order. This means JOI-kun takes an action of Type 1 on $j$-th day. The size of the fish $X_j$ becomes $Y_j$.
  • If $T_j = 2$, this line contains two more space separated integers $L_j$, $R_j$, in this order. This means JOI-kun takes an action of Type 2 on $j$-th day. JOI-kun performs a thought experiment for fishes whose indices are between $L_j$ and $R_j$, inclusive.

출력

For each action of Type 2 (i.e., for each $j$ ($1 ≤ j ≤ Q$) with $T_j = 2$), in order, write the number of possible indices of surviving fishes to the standard output. The outputs should be separated by line breaks.

제한

  • $1 ≤ N ≤ 100\,000$.
  • $1 ≤ Q ≤ 100\,000$.
  • $1 ≤ A_i ≤ 1\,000\,000\,000$ ($= 10^9$) ($1 ≤ i ≤ N$).
  • $T_j$ is either $1$ or $2$ ($1 ≤ j ≤ Q$).
  • $1 ≤ X_j ≤ N$ ($1 ≤ j ≤ Q$).
  • $1 ≤ Y_j ≤ 1\,000\,000\,000$ ($= 10^9$) ($1 ≤ j ≤ Q$).
  • $1 ≤ L_j ≤ R_j ≤ N$ ($1 ≤ j ≤ Q$).

서브태스크

번호배점제한
15

$N ≤ 500$, $Q ≤ 500$.

28

$Q = 1$, $T_j = 2$, $L_j = 1$, $R_j = N$ ($1 ≤ j ≤ Q$).

312

$Q ≤ 1\,000$.

423

$T_j = 2$ ($1 ≤ j ≤ Q$).

535

For each $j$ ($1 ≤ j ≤ Q$) with $T_j = 2$, the equalities $L_j = 1$ and $R_j = N$ are satisfied.

617

No additional constraints.

예제 입력 1

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

예제 출력 1

5
2
2
3
1

For $6$ days, JOI-kun takes the following actions.

  • On the first day, JOI-kun performs a thought experiment for the fishes $1$, $2$, $3$, $4$, $5$.
  • On the second day, JOI-kun performs a thought experiment for the fishes $1$, $2$, $3$.
  • On the third day, JOI-kun gives a special feed to the fish $3$. After that, the size of the fish $3$ becomes $1$.
  • On the fourth day, JOI-kun performs a thought experiment for the fishes $2$, $3$, $4$, $5$.
  • On the fifth day, JOI-kun performs a thought experiment for the fishes $1$, $2$, $3$, $4$, $5$.
  • On the sixth day, JOI-kun performs a thought experiment for the fishes $2$, $3$, $4$.

The results of a thought experiment for the first day are as follows.

  • The sizes of the fishes in the aquarium are $6$, $4$, $2$, $2$, $6$ from left to right.
  • For example, the fish $2$ survives in the aquarium by the following process. (An array specifies the sizes of the fishes in the aquarium from left to right. A bold face character specifies the size of the fish $2$.)
    • $[6, \textbf{4}, 2, 2, 6]$ (Initial State) → $[6, \textbf{4}, 4, 6]$ (The fish $4$ eats the fish $3$) → $[6, \textbf{8}, 6]$ (The fish $2$ eats the fish $4$) → $[\textbf{14}, 6]$ (The fish $2$ eats the fish $1$) → $[\textbf{20}]$ (The fish $2$ eats the fish $5$)
  • Similarly, the possible indices of surviving fishes are $1$, $2$, $3$, $4$, $5$. Hence there are five possibilities.

This sample input satisfies the constraints of Subtasks 1, 3, 6.

예제 입력 2

13
10 4 2 5 20 5 4 8 20 10 3 3 7
1
2 1 13

예제 출력 2

7

This sample input satisfies the constraints of all the subtasks.

예제 입력 3

12
32 32 4 1 1 1 1 4 4 16 32 128
7
2 1 12
2 2 6
2 8 10
2 1 9
2 3 8
2 5 9
2 2 12

예제 출력 3

12
1
1
2
6
2
1

This sample input satisfies the constraints of Subtasks 1, 3, 4, 6.

예제 입력 4

10
2 3 5 10 1 3 4 9 5 2
8
2 1 10
1 10 5
2 1 10
1 4 1000000000
2 1 10
1 8 20
1 4 8
2 1 10

예제 출력 4

4
6
1
6

This sample input satisfies the constraints of Subtasks 1, 3, 5, 6.

채점 및 기타 정보

  • 예제는 채점하지 않는다.