Master Zhu and Magic Numbers

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

문제

Master Zhu has nn magic numbers. The ii-th number a_ia\_i can be represented by a binary string of length ii which can contain leading zeroes. When we reverse and concatenate these binary strings, we get a long string ss of length n(n+1)2\frac{n (n + 1)}{2}. A substring from s\left\[\frac{i (i - 1)}{2}\right] to s\left\[\frac{i (i + 1)}{2} - 1\right] inclusive is the binary representation of a_ia\_i, from lowest to highest digit. Here, the long string ss is indexed starting from zero.

One day, Rin inputs Master Zhu's magic numbers into a program to create nn new magic numbers. The ii-th new number is b_ib\_i. Here is the code of the program in a C-like language.

for (int i = 1; i <= n; i++) {
  b[i] = 0,
  flag[i] = 0;
}

for (int i = 1; i <= n; i++) {
  for (int j = 1; j <= n; j++) {
    if (((1 << (j - 1)) & a[i]) > 0) {
      if (!flag[i]) {
        b[i] = b[j],
        flag[i] = 1;
      } else {
        b[i] = b[i] & b[j];
      }
    }
  }
  b[i] = b[i] ^ (1 << (i - 1));
}

In the code above, "x << y" is bitwise shift to the left, which is equivalent to multiplying x by 2y2^{\texttt{y}}, "x & y" is bitwise AND, and "x ^ y" is bitwise XOR. We assume that the numbers a_ia\_i and b_ib\_i can have arbitrarily many bits.

After that, Rin wants to ask qq questions. The ii-th question is a number c_ic\_i which can be represented in binary notation as a string of length len_i\mathit{len}\_i and can contain leading zeroes. When we reverse and concatenate these binary strings, we get a long string tt of length L_qL\_q, where L_k=_i=1klen_iL\_k = \sum\limits\_{i = 1}^{k} \mathit{len}\_i. A substring from t\left\[L\_{i - 1}\right] to t\left\[L\_i - 1\right] inclusive is the binary representation of c_ic\_i, from lowest to highest digit. Here, the long string tt is indexed starting from zero.

For each question, Rin requires Illya to calculate the number d_id\_i:

for (int i = 1; i <= q; i++) {
  d[i] = 0;
  for (int j = 1; j <= min (n, len[i]); j++) {
    if (((1 << (j - 1)) & c[i]) > 0) {
      d[i] = d[i] | b[j];
    }
  }
}

Here, "x | y" is bitwise OR. We assume that the numbers c_ic\_i and d_id\_i can have arbitrarily many bits.

The answer to the ii-th question is the number of ones in the binary representation of d_id\_i. Help Illya answer all the questions!

입력

The first line of the input contains two integers nn and mm denoting the number of magic numbers and the number of ones in the long string ss (1n50001 \leq n \leq 5000, 1m1061 \leq m \leq 10^6).

The second line contains mm integers, the ii-th integer p_ip\_i denotes that s\[p_i]=1s\[p\_i] = 1, and all other digits of ss are equal to 00 (0p_i<n(n+1)20 \leq p\_i < \frac{n (n + 1)}{2}, all p_ip\_i are distinct).

The third line contains two integers qq and rr denoting the number of questions and the number of ones in the long string tt (1q50001 \le q \le 5000, 1r1061 \le r \le 10^6).

The fourth line contains qq integers, the ii-th integer len_i\mathit{len}\_i denotes the length of binary representation of the ii-th query c_ic\_i (1len_i1091 \leq \mathit{len}\_i \leq 10^9). It is guaranteed that L_q=_i=1qlen_iL\_q = \sum\limits\_{i = 1}^{q} \mathit{len}\_i is at most 10910^9.

The fifth line contains rr integers, the ii-th integer z_iz\_i denotes that t\[z_i]=1t\[z\_i] = 1, and all other digits of tt are equal to 00 (0z_i<L_q0 \le z\_i < L\_q, all z_iz\_i are distinct).

출력

For each question ii, print a single line with a single integer: the number of ones in the binary representation of d_id\_i.