#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T& c) {
  return c.size();
}
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const int maxn = 1058576;
long long F[30][2];
int cur[30];
int a[maxn];
int n, m, q, sn;
int BIT[maxn];
int maxso;
int u;
long long res;
void update(int i, int gt) {
  if (i == 0) return;
  while (i <= maxso) {
    BIT[i] = BIT[i] + gt;
    i = i + (i & (-i));
  }
}
long long get(int i) {
  long long gt = 0;
  while (i >= 1) {
    gt = gt + BIT[i];
    i = i - (i & (-i));
  }
  return gt;
}
void roirachoa() {
  vector<int> b(a + 1, a + sn + 1);
  sort(b.begin(), b.end());
  vector<int>::iterator it = unique(b.begin(), b.end());
  b.resize(distance(b.begin(), it));
  maxso = b.size();
  for (int i = 1; i <= sn; i++)
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
}
int main() {
  scanf("%d", &n);
  sn = (1 << n);
  for (int i = 1; i <= sn; i++) scanf("%d", &a[i]);
  roirachoa();
  memset(BIT, 0, sizeof(BIT));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sn; j += (1 << i)) {
      for (int k = j; k <= j + (1 << (i - 1)) - 1; k++) update(a[k], 1);
      for (int k = j + (1 << (i - 1)); k <= j + (1 << i) - 1; k++)
        F[i][0] += get(a[k] - 1);
      for (int k = j; k <= j + (1 << (i - 1)) - 1; k++) update(a[k], -1);
      for (int k = j + (1 << (i - 1)); k <= j + (1 << i) - 1; k++)
        update(a[k], 1);
      for (int k = j; k <= j + (1 << (i - 1)) - 1; k++)
        F[i][1] += get(a[k] - 1);
      for (int k = j + (1 << (i - 1)); k <= j + (1 << i) - 1; k++)
        update(a[k], -1);
    }
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &u);
    for (int i = u; i >= 1; i--) cur[i] = 1 - cur[i];
    res = 0;
    for (int i = 1; i <= n; i++) res = res + F[i][1 - cur[i]];
    printf("%I64d\n", res);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
