#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = (1 << 20) + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>
inline void gadd(T1 &a, T2 b) {
  a = (a + b) % Z;
}
int n, m, top;
int a[N], b[N];
long long num[21];
long long sum[21];
int v[N];
void add(int x, int val) {
  for (; x <= top; x += x & -x) v[x] += val;
}
int cnt(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret += v[x];
  return ret;
}
void init() {
  for (int i = 1; i <= n; ++i) {
    int l = 1 << i;
    int d = m / l;
    sum[i] = 0;
    num[i] = 0;
    int st = 0;
    while (d--) {
      for (int j = l / 2 + 1; j <= l; ++j) add(a[st + j], 1);
      for (int j = 1; j <= l / 2; ++j) {
        int tmp1 = cnt(a[st + j] - 1);
        int tmp2 = cnt(a[st + j]);
        num[i] += tmp1;
        sum[i] += l / 2 - (tmp2 - tmp1);
      }
      for (int j = l / 2 + 1; j <= l; ++j) add(a[st + j], -1);
      st += l;
    }
  }
}
int main() {
  while (~scanf("%d", &n)) {
    m = 1 << n;
    for (int i = 1; i <= m; ++i) scanf("%d", &a[i]), b[i] = a[i];
    sort(b + 1, b + m + 1);
    top = unique(b + 1, b + m + 1) - b - 1;
    for (int i = 1; i <= m; ++i)
      a[i] = lower_bound(b + 1, b + top + 1, a[i]) - b;
    init();
    int q;
    scanf("%d", &q);
    while (q--) {
      int x;
      scanf("%d", &x);
      for (int i = x; i >= 1; --i) num[i] = sum[i] - num[i];
      long long ans = 0;
      for (int i = 1; i <= n; ++i) ans += num[i];
      printf("%lld\n", ans);
    }
  }
  return 0;
}
