| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 109 | 48 | 41 | 45.055% |
JOI-kun is breeding $N$ fish in a large tank, and each fish is numbered from $1$ to $N$.
JOI-kun has two types of fish food, A and B, both in sufficient quantities. When one piece of food is added to the aquarium, exactly one fish eats it (any fish could potentially eat it), and depending on the type of food and which fish ate it, the intelligence of the fish changes as follows:
Currently, the intelligence of all fish is $0$. JOI-kun wants to make the intelligence of fish $i$ ($1 ≤ i ≤ N$) equal to its ideal intelligence $C_i$, but it may not always be possible.
Therefore, he considered $Q$ questions. The $j$-th question ($1 ≤ j ≤ Q$) is as follows:
Write a program that, given information about JOI-kun’s fish and information about the questions, answers his questions.
Read the following data from the standard input.
$N$ $D$
$C_1$ $C_2$ $\cdots$ $C_N$
$Q$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_Q$ $R_Q$
Write $Q$ lines to the standard input. In the $j$-th line ($1 ≤ j ≤ Q$), if it is possible to reach the state where all fish $L_j , L_j + 1, \dots , R_j$ have their exact ideal intelligence values, output the minimum number of pieces of type A food that needs to be put into the tank. Otherwise, output -1.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 9 | $N ≤ 3\, 000$, $Q ≤ 3\, 000$. |
| 2 | 7 | $C_i ≤ 1$ ($1 ≤ i ≤ N$). |
| 3 | 28 | $D = 1$. |
| 4 | 20 | $C_i ≥ C_{i+1}$ ($1 ≤ i ≤ N - 1$). |
| 5 | 36 | No additional constraints. |
4 2 3 1 2 1 1 1 3
1
For example, in the following case, all fish $1$, $2$, $3$ eventually have their exact ideal intelligence values, and the number of pieces of type A food put into the tank is $1$.
Since it is impossible to reach the state where all fish $1$, $2$, $3$ have the exact ideal intelligence values without putting any piece of type A food, output $1$.
This sample input satisfies the constraints of Subtasks 1, 5.
4 2 0 1 0 1 3 1 2 2 3 1 1
0 -1 0
This sample input satisfies the constraints of Subtasks 1, 2, 5.
5 1 3 1 4 1 5 3 1 5 2 4 3 5
5 3 3
This sample input satisfies the constraints of Subtasks 1, 3, 5.
6 3 16 14 13 8 6 5 4 1 4 2 5 3 3 1 6
9 8 0 -1
This sample input satisfies the constraints of Subtasks 1, 4, 5.