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

34351번 - Bubble Sort Machine 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB24131252.174%

문제

JOI-kun, an algorithm researcher, has developed a machine called the Bubble Sort Machine.

The Bubble Sort Machine operates on an integer sequence $a = (a_1, a_2, \dots , a_N)$ of length $N$. To activate the Bubble Sort Machine, the initial values $A_i$ are provided as input for each $a_i$ (1ドル ≤ i ≤ N$). Each time Button 1 on the Bubble Sort Machine is pressed, the machine modifies the sequence $a$ in the following way:

  • For each $i = 1, 2, \dots , N − 1$ in order, if $a_i > a_{i+1},ドル then the values of $a_i$ and $a_{i+1}$ are swapped.

To make the Bubble Sort Machine even more appealing, JOI-kun decided to add the following feature:

  • When Button 2 is pressed and integers $l$ and $r$ satisfying 1ドル ≤ l ≤ r ≤ N$ are given as input, the machine outputs the value of $a_l + a_{l+1} + \cdots + a_r$.

Given the initial values of the integer sequence and the sequence of operations on the Bubble Sort Machine, write a program that computes the outputs produced by Button 2.

입력

Read the following data from the standard input.

$N$

$A_1$ $A_2$ $\cdots$ $A_N$

$Q$

(Query 1ドル$)

(Query 2ドル$)

$\vdots$

(Query $Q$)

Here, $Q$ is the number of operations performed on the Bubble Sort Machine. Each (Query $j$) (1ドル ≤ j ≤ Q$) consists space separated integers. Let $T_j$ denote the first integer of (Query $j$). The content of this line is one of the following.

  • If $T_j = 1,ドル this line contains no additional integers. This means that the $j$-th operation on the Bubble Sort Machine is pressing Button 1.
  • If $T_j = 2,ドル this line contains two more integers, $L_j$ and $R_j,ドル in that order. This means that the $j$-th operation on the Bubble Sort Machine is pressing Button 2 with the integers $L_j$ and $R_j$ as input.

출력

For each operation where Button 2 is pressed, that is, for each $j$ (1ドル ≤ j ≤ Q$) such that $T_j = 2,ドル output the integer produced by the Bubble Sort Machine on a separate line in the order of the queries.

제한

  • 2ドル ≤ N ≤ 500,円 000$.
  • 1ドル ≤ A_i ≤ 10^9$ (1ドル ≤ i ≤ N$).
  • 1ドル ≤ Q ≤ 500,円 000$.
  • $T_j$ is either 1ドル$ or 2ドル$ (1ドル ≤ j ≤ Q$).
  • If $T_j = 2,ドル 1ドル ≤ L_j ≤ R_j ≤ N$ (1ドル ≤ j ≤ Q$).
  • Given values are all integers.

서브태스크

번호배점제한
15

The number of $j$ (1ドル ≤ j ≤ Q$) such that $T_j = 1$ is at most 10ドル$.

211

$N ≤ 150,円 000,ドル $Q ≤ 150,円 000,ドル $L_j = R_j = 1$ if $T_j = 2$ (1ドル ≤ j ≤ Q$).

315

$N ≤ 150,円 000,ドル $Q ≤ 150,円 000,ドル 1ドル ≤ A_i ≤ 2$ (1ドル ≤ i ≤ N$).

423

$N ≤ 150,円 000,ドル $Q ≤ 150,円 000,ドル $L_j = R_j$ if $T_j = 2$ (1ドル ≤ j ≤ Q$).

529

$N ≤ 150,円 000,ドル $Q ≤ 150,円 000$.

617

No additional constraints.

예제 입력 1

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

예제 출력 1

13
3
12
5

First, the initial values $a_1 = 5,ドル $a_2 = 3,ドル $a_3 = 5,ドル and $a_4 = 2$ are given, initializing $a = (5, 3, 5, 2)$. The operations of the Bubble Sort Machine proceed as follows:

  1. Button 2 is pressed with $l = 1,ドル $r = 3$ as input. The Bubble Sort Machine outputs $a_1 + a_2 + a_3 = 13$.
  2. Button 1 is pressed. For $i = 1, 2, 3,ドル the following operations are performed in order:
    • For $i = 1$: Since $a_1 > a_2$ holds, their values are swapped, resulting in $a = (3, 5, 5, 2)$.
    • For $i = 2$: Since $a_2 > a_3$ does not hold, no change is made to $a$.
    • For $i = 3$: Since $a_3 > a_4$ holds, their values are swapped, resulting in $a = (3, 5, 2, 5)$.
  3. Button 2 is pressed with $l = 1,ドル $r = 1$ as input. The Bubble Sort Machine outputs $a_1 = 3$.
  4. Button 2 is pressed with $l = 2,ドル $r = 4$ as input. The Bubble Sort Machine outputs $a_2 + a_3 + a_4 = 12$.
  5. Button 1 is pressed. For $i = 1, 2, 3,ドル the following operations are performed in order:
    • For $i = 1$: Since $a_1 > a_2$ does not hold, no change is made to $a$.
    • For $i = 2$: Since $a_2 > a_3$ holds, their values are swapped, resulting in $a = (3, 2, 5, 5)$.
    • For $i = 3$: Since $a_3 > a_4$ does not hold, no change is made to $a$.
  6. Button 2 is pressed with $l = 1,ドル $r = 2$ as input. The Bubble Sort Machine outputs $a_1 + a_2 = 5$.

This sample input satisfies the constraints of subtasks 1, 5, and 6.

예제 입력 2

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

예제 출력 2

3
4
4

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

힌트

출처

Contest > JOI Open Contest > JOI Open Contest 2025 1번

채점 및 기타 정보

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

출처

대학교 대회

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

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