#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1200005;
const long long Z = 1e6;
long long n, q, ar[MAXN], tmp[MAXN], cnt1[MAXN], cnt2[MAXN], mi[30];
void merge(long long dep, long long l, long long r) {
  if (l == r) {
    scanf("%lld", &ar[l]);
    return;
  }
  long long mid = l + r >> 1, p = 0, i = l, j = mid + 1;
  merge(dep - 1, l, mid);
  merge(dep - 1, mid + 1, r);
  while (i <= mid && j <= r) {
    if (ar[i] <= ar[j]) {
      tmp[p++] = ar[i++];
    } else {
      tmp[p++] = ar[j++];
      cnt1[dep] += mid - i + 1;
    }
  }
  while (i <= mid) tmp[p++] = ar[i++];
  while (j <= r) tmp[p++] = ar[j++];
  i = l, j = mid + 1;
  while (i <= mid && j <= r) {
    if (ar[i] < ar[j]) {
      i++;
      cnt2[dep] += r - j + 1;
    } else {
      j++;
    }
  }
  for (long long k = 0; k < p; k++) {
    ar[l + k] = tmp[k];
  }
}
int main() {
  mi[0] = 1;
  for (long long i = 1; i <= 25; i++) mi[i] = mi[i - 1] << 1;
  scanf("%lld", &n);
  merge(n, 1, 1ll << n);
  scanf("%lld", &q);
  for (long long inp1, i = 1; i <= q; i++) {
    long long ans = 0;
    scanf("%lld", &inp1);
    for (long long j = 1; j <= inp1; j++) {
      swap(cnt1[j], cnt2[j]);
    }
    for (long long j = 1; j <= n; j++) {
      ans += cnt1[j];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
