Modern Machine

아직 제출이 없습니다시간 제한2.5초메모리 제한1024 MB

문제

Bitaro is given JOI machine as a birthday present. JOI machine consists of one ball, NN light tiles, and MM buttons. The light tiles are numbered from 11 to NN. When Bitaro turns the power on, Light tile ii (1iN1 ≤ i ≤ N) emit light of color C_iC\_i (blue (B) or red (R)). The buttons are numbered from 11 to MM. If Bitaro pushes Button jj (1jM1 ≤ j ≤ M), the following happen.

  1. The ball is placed on Light tile A_jA\_j.

  2. Light tile A_jA\_j becomes red (regardless of its original color).

  3. The following operations are performed until the ball is removed.

    • Let pp be the index of the light tile where the ball is currently placed.
    • If Light tile pp is blue,
      • Light tile pp becomes red. After that, if p=1p = 1, the ball is removed. Otherwise, the ball moves to Light tile p1p - 1.
    • If Light tile pp is red,
      • Light tile pp becomes blue. After that, if p=Np = N, the ball is removed. Otherwise, the ball moves to Light tile p+1p + 1.

Bitaro is interested in JOI machine. He plans to perform QQ experiments. In the kk-th experiment (1kQ1 ≤ k ≤ Q), after Bitaro turns the power on, Bitaro pushes Buttons L_k,L_k+1,,R_kL\_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.

NN MM

C_1C_2C_NC\_1C\_2 \cdots C\_N

A_1A\_1 A_2A\_2 \cdots A_MA\_M

QQ

L_1L\_1 R_1R\_1

L_2L\_2 R_2R\_2

\vdots

L_QL\_Q R_QR\_Q

출력

Write QQ lines to the standard output. In the kk-th line (1kQ1 ≤ k ≤ Q), the output should contain the number of light tiles whose colors are red when the kk-th experiment finishes.

제한

  • 3N120,0003 ≤ N ≤ 120\\,000.
  • 1M120,0001 ≤ M ≤ 120\\,000.
  • C_iC\_i (1iN1 ≤ i ≤ N) is either B or R.
  • 1A_jN1 ≤ A\_j ≤ N (1jM1 ≤ j ≤ M).
  • 1Q120,0001 ≤ Q ≤ 120\\,000.
  • 1L_kR_kM1 ≤ L\_k ≤ R\_k ≤ M (1kQ1 ≤ k ≤ Q).
  • NN, MM, A_jA\_j, QQ, L_kL\_k, R_kR\_k are integers.