#include <bits/stdc++.h>
using namespace std;
long long n, m, k, A[1500005], B[1500005], I[25], E[25], D[25];
long long f(long long n) { return (n * (n - 1)) / 2; }
void MergeSort(long long bas, long long son, long long lvl) {
  if (bas == son) return;
  long long ort = (bas + son) / 2;
  MergeSort(bas, ort, lvl - 1);
  MergeSort(ort + 1, son, lvl - 1);
  long long j = ort + 1;
  for (long long i = bas; i <= ort; i++) {
    while (j <= son && A[i] > A[j]) j++;
    I[lvl] += j - ort - 1;
  }
  long long i = bas, l = bas;
  j = ort + 1;
  while (i <= ort && j <= son) {
    if (A[i] < A[j])
      B[l++] = A[i++];
    else
      B[l++] = A[j++];
  }
  while (i <= ort) B[l++] = A[i++];
  while (j <= son) B[l++] = A[j++];
  i = bas;
  while (i <= son) {
    j = i + 1;
    while (B[i] == B[j]) j++;
    E[lvl] += (j - i) * (j - i - 1) / 2;
    i = j;
  }
  for (long long i = bas; i <= son; i++) A[i] = B[i];
}
int main() {
  long long x;
  scanf("%lld", &n);
  k = 1 << n;
  for (long long i = 1; i <= k; i++) scanf("%lld", A + i);
  MergeSort(1, k, n);
  for (long long i = 1; i <= n; i++) D[i] = I[i];
  for (long long i = 1; i <= n; i++) I[i] += I[i - 1];
  scanf("%lld", &m);
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", &x);
    long long t = I[x];
    for (long long i = 1; i <= x; i++)
      I[i] = ((1 << (n - i)) * f(1 << i) - E[i]) - I[i];
    for (long long i = x + 1; i <= n; i++) I[i] += I[x] - t;
    printf("%lld\n", I[n]);
  }
  return 0;
}
