#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 20;
const long long int size = 1 << maxn;
long long int n, m, q, t;
long long int levels;
long long int a[size + 1];
long long int temp[size + 1];
long long int inv[maxn + 1][2];
long long int type[maxn + 1];
void merge(long long int l, long long int r, long long int lvl) {
  long long int i, j, k, mid;
  long long int li, ri;
  mid = (l + r) / 2;
  li = ri = 0;
  i = l;
  j = mid + 1;
  k = l;
  while (i <= mid && j <= r) {
    if (a[i] <= a[j]) {
      temp[k] = a[i];
      k++;
      i++;
    } else {
      temp[k] = a[j];
      k++;
      j++;
      li += mid - i + 1;
    }
  }
  i = l;
  j = mid + 1;
  k = l;
  while (i <= mid && j <= r) {
    if (a[j] <= a[i]) {
      temp[k] = a[j];
      k++;
      j++;
    } else {
      temp[k] = a[i];
      k++;
      i++;
      ri += r - j + 1;
    }
  }
  while (i <= mid) temp[k++] = a[i++];
  while (j <= r) temp[k++] = a[j++];
  inv[lvl][0] += li;
  inv[lvl][1] += ri;
  for (i = l; i <= r; i++) a[i] = temp[i];
}
void merge_sort(long long int l, long long int r, long long int lvl) {
  if (l == r) return;
  long long int mid = (l + r) / 2;
  merge_sort(l, mid, lvl - 1);
  merge_sort(mid + 1, r, lvl - 1);
  merge(l, r, lvl);
}
void solve() {
  cin >> n;
  levels = n;
  n = (1 << n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  merge_sort(1, n, levels);
  cin >> m;
  while (m--) {
    cin >> q;
    for (int i = 1; i <= q; i++) type[i] = !type[i];
    long long int res = 0;
    for (int i = 1; i <= levels; i++) res += inv[i][type[i]];
    cout << res << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
