시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2.5 초 | 1024 MB | 4 | 2 | 2 | 100.000% |
Bitaro is given JOI machine as a birthday present. JOI machine consists of one ball, $N$ light tiles, and $M$ buttons. The light tiles are numbered from $1$ to $N$. When Bitaro turns the power on, Light tile $i$ ($1 ≤ i ≤ N$) emit light of color $C_i$ (blue (B
) or red (R
)). The buttons are numbered from $1$ to $M$. If Bitaro pushes Button $j$ ($1 ≤ j ≤ M$), the following happen.
Bitaro is interested in JOI machine. He plans to perform $Q$ experiments. In the $k$-th experiment ($1 ≤ k ≤ Q$), after Bitaro turns the power on, Bitaro pushes Buttons $L_k, L_{k + 1}, \dots , R_k$ in this order. After Bitaro pushes a button, he will not push the next button and wait until the ball is removed.
Given information of JOI machine and the experiments, write a program which calculates, for each experiment, the number of light tiles whose colors are red when the experiment finishes.
Read the following data from the standard input.
$N$ $M$
$C_1C_2 \cdots C_N$
$A_1$ $A_2$ $\cdots$ $A_M$
$Q$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_Q$ $R_Q$
Write $Q$ lines to the standard output. In the $k$-th line ($1 ≤ k ≤ Q$), the output should contain the number of light tiles whose colors are red when the $k$-th experiment finishes.
B
or R
.번호 | 배점 | 제한 |
---|---|---|
1 | 3 | $N ≤ 300$, $M ≤ 300$, $Q = 1$. |
2 | 12 | $N ≤ 7\,000$, $M ≤ 7\,000$, $Q = 1$. |
3 | 10 | $Q ≤ 5$. |
4 | 11 | $N = 10$, and $C_i$ is |
5 | 26 | There exists an integer $t$ ($0 ≤ t ≤ N$) such that $C_i$ is |
6 | 17 | $A_j ≤ 20$ or $A_j > N - 20$ ($1 ≤ j ≤ M$). |
7 | 21 | No additional constraints. |
5 1 RBRRB 4 1 1 1
1
The first experiment proceeds as follows.
After the experiment, Light tile $1$ is the only light tile whose current color is red. Therefore, output $1$.
This sample input satisfies the constraints of Subtasks 1, 2, 3, 6, 7.
5 3 RBRBR 1 3 4 2 2 3 1 3
5 0
For the first experiment, Light tiles $1$, $2$, $3$, $4$, $5$ are the light tiles whose current colors are red after the experiment. Since there are five such light tiles, output $5$.
For the second experiment, there is no light tile whose current color is red after the experiment. Therefore, output $0$.
This sample input satisfies the constraints of Subtasks 3, 6, 7.
10 3 BBRRBRBRRB 2 10 5 1 1 3
2
This sample input satisfies the constraints of Subtasks 1, 2, 3, 6, 7.
10 10 RRRRRRRRRR 3 1 4 1 5 9 2 6 5 3 5 1 7 2 8 3 9 4 10 1 10
4 8 10 0 9
This sample input satisfies the constraints of Subtasks 3, 4, 5, 6, 7.
10 10 RRRBBBBBBB 3 1 4 1 5 9 2 6 5 3 5 1 10 2 9 3 8 4 7 5 6
2 6 0 10 7
This sample input satisfies the constraints of Subtasks 3, 5, 6, 7.
30 10 RRRBBRBBBRBBBRBRBRRRRRBBBBRBRR 3 28 2 29 1 30 6 14 7 7 10 1 10 2 3 2 5 2 8 3 3 3 6 4 5 4 7 5 9 10 10
21 15 15 4 17 16 14 20 12 23
This sample input satisfies the constraints of Subtasks 6, 7.