#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 20) + 10;
int c[MAXN];
int a[MAXN];
vector<pair<int, int> > v;
long long sum[22][2];
int sta[22];
int n, cnt;
void add(int pos, int v) {
  while (pos <= cnt) {
    c[pos] += v;
    pos += pos & -pos;
  }
}
int getsum(int pos) {
  int ret = 0;
  while (pos > 0) {
    ret += c[pos];
    pos -= pos & -pos;
  }
  return ret;
}
void build(int l, int r, int q) {
  int mid = l + r >> 1;
  if (l == r) return;
  for (int i = l; i <= mid; i++) add(a[i], 1);
  for (int i = mid + 1; i <= r; i++) sum[q][0] += mid - l + 1 - getsum(a[i]);
  for (int i = l; i <= mid; i++) add(a[i], -1);
  for (int i = mid + 1; i <= r; i++) add(a[i], 1);
  for (int i = l; i <= mid; i++) sum[q][1] += mid - l + 1 - getsum(a[i]);
  for (int i = mid + 1; i <= r; i++) add(a[i], -1);
  build(l, mid, q - 1);
  build(mid + 1, r, q - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++)
    scanf("%d", &a[i]), v.push_back(make_pair(a[i], i));
  sort(v.begin(), v.end());
  cnt = 1;
  for (int i = 0; i < (1 << n); i++)
    if (i == 0 || v[i].first == v[i - 1].first)
      a[v[i].second] = cnt;
    else
      a[v[i].second] = ++cnt;
  build(0, (1 << n) - 1, n);
  int qq;
  scanf("%d", &qq);
  while (qq--) {
    int st;
    scanf("%d", &st);
    for (int j = st; j >= 1; j--) sta[j] = 1 - sta[j];
    long long ans = 0;
    for (int j = 1; j <= n; j++) ans += sum[j][sta[j]];
    printf("%I64d\n", ans);
  }
  return 0;
}
