#include <bits/stdc++.h>
using namespace std;
vector<int> st, pq;
int a[2222222];
int m, n, f[222];
long long gt[222][2];
void build(int fl, int dau, int cuoi) {
  int mid = (dau + cuoi) / 2;
  st.clear();
  pq.clear();
  for (int i = dau; i <= mid; i++) st.push_back(a[i]);
  for (int i = mid + 1; i <= cuoi; i++) pq.push_back(a[i]);
  sort(st.begin(), st.end());
  sort(pq.begin(), pq.end());
  int p;
  p = 0;
  for (int i = 0; i <= int(st.size()) - 1; i++) {
    while ((p <= int(pq.size()) - 1) && (pq[p] < st[i])) p++;
    gt[fl][0] += p;
  }
  p = 0;
  for (int i = 0; i <= int(pq.size()) - 1; i++) {
    while ((p <= int(st.size()) - 1) && (st[p] < pq[i])) p++;
    gt[fl][1] += p;
  }
  if (fl > 1) {
    build(fl - 1, dau, mid);
    build(fl - 1, mid + 1, cuoi);
  }
}
int main() {
  cin >> m;
  n = 1 << m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(gt, 0, sizeof(gt));
  build(m, 1, n);
  memset(f, 0, sizeof(f));
  long long ans = 0;
  for (int i = 0; i <= m; i++) ans += gt[i][0];
  int query, x;
  cin >> query;
  for (int i = 1; i <= query; i++) {
    scanf("%d", &x);
    for (int j = 0; j <= x; j++) {
      ans += gt[j][1 - f[j]] - gt[j][f[j]];
      f[j] = 1 - f[j];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
