#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005, MOD = 7 + 1e9;
const int Max_N = 1 << 21;
int x[Max_N];
long long bigger[32], smaller[32];
void Divide(int L, int R, int dep) {
  if (L == R) return;
  int M = (L + R) >> 1;
  Divide(L, M, dep + 1);
  Divide(M + 1, R, dep + 1);
  for (int i = M + 1; i <= R; i++) {
    bigger[dep] +=
        (long long)((x + M + 1) - upper_bound(x + L, x + M + 1, x[i]));
    smaller[dep] += (long long)(lower_bound(x + L, x + M + 1, x[i]) - (x + L));
  }
  sort(x + L, x + R + 1);
}
int main() {
  int n, i, m, q;
  long long ans;
  while (cin >> n) {
    for (i = 1; i <= (1 << n); i++) scanf("%d", &x[i]);
    memset(bigger, 0, sizeof(bigger));
    memset(smaller, 0, sizeof(smaller));
    Divide(1, 1 << n, 1);
    ans = 0;
    for (i = 1; i <= n; i++) ans += bigger[i];
    cin >> m;
    while (m--) {
      scanf("%d", &q);
      for (i = n - q + 1; i <= n; i++) {
        ans -= bigger[i];
        ans += smaller[i];
        swap(bigger[i], smaller[i]);
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
