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

24952번 - Fish 2 서브태스크다국어

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

문제

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.

힌트

출처

Camp > JOI Spring Training Camp > JOI 2021/2022 Spring Training Camp 4-2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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