| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 2048 MB | 195 | 37 | 25 | 23.585% |
Sam has some apricot seeds, and he wants to sort them in non-decreasing order based on size. He uses a unique method to sort the apricot seeds, described as follows:
Given $n$ apricot seeds, Sam performs a total of $n - 1$ steps to sort them. For each step $k$ from 1ドル$ to $n - 1$:
Sam's friend Tom quickly realizes that this is the famous bubble sorting algorithm. To illustrate the inefficiency of this algorithm to Sam, Tom decides to ask Sam $q$ questions. A question is represented as a tuple $[s, e, m, l, r]$. For given a sequence of $n$ seeds, each question $[s, e, m, l, r]$ asks for the sum of the sizes of seeds from position $l$ to $r$ of the (partially) sorted subsequence after applying the first $m$ steps of Sam's method to the subsequence of seeds from position $s$ to $e$ of the initial sequence.
For instance, consider four ($n = 4$) seeds with sizes of $(1,3,4,2)$ and two ($q = 2$) questions $[2,4,1,2,2]$ and $[1,4,2,3,4]$. For the first question, the subsequence of the sizes from the second ($s = 2$) seed to the fourth ($e = 4$) seed is $(3,4,2)$. After applying one step ($m = 1$) of Sam’s method, it becomes $(3,2,4)$. The sum of the sizes of seeds from the second position ($l = 2$) to the second position ($r = 2$) in this (partially) sorted subsequence is 2ドル$. For the second question, the subsequence is $(1,3,4,2)$. After applying two steps, it becomes $(1,2,3,4)$. The sum of the sizes of seeds from position 3ドル$ to 4ドル$ in this (partially) sorted sequence is 3ドル + 4 = 7$.
Given a sequence of $n$ seeds and $q$ questions, write a program that computes the answer for each question.
Your program is to read from standard input. The input starts with a line containing two integers, $n$ and $q$ (2ドル ≤ n ≤ 1,000円,000円,ドル 1ドル ≤ q ≤ 500,000円$), where $n$ represents the number of seeds and $q$ represents the number of questions. The second line contains $n$ integers, separated by spaces, representing the sizes of the apricot seeds in their initial order. Each size is between 1ドル$ and 10ドル^9,ドル both inclusive. Each of the next $q$ lines contains five positive integers $s,ドル $e,ドル $m,ドル $l,ドル $r$ of query $[s, e, m, l, r],ドル separated by spaces, representing a question, where 1ドル ≤ s < e ≤ n,ドル 1ドル ≤ m ≤ e - s,ドル and 1ドル ≤ l ≤ r ≤ e - s + 1$.
Your program is to write to standard output. For each of the $q$ questions, output one line with the answer. The answer for a question $[s, e, m, l, r]$ is the sum of the sizes of seeds from position $l$ to $r$ of the partially sorted subsequence after applying the first $m$ steps of Sam's method to the subsequence of seeds from position $s$ to $e$ of the input sequence.
4 2 1 3 4 2 2 4 1 2 2 1 4 2 3 4
2 7
5 3 4 2 5 1 3 1 5 1 3 3 1 3 1 3 3 2 4 2 1 2
1 5 3
6 2 5 4 5 1 1 4 3 6 1 1 3 1 6 1 1 4
6 11
ICPC > Regionals > Asia Pacific > Korea > Asia Regional - Seoul 2023 A번
Camp > Petrozavodsk Programming Camp > Winter 2024 > Day 6: K-ontest J번