#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
inline int FIX(int a) { return (a % Mod + Mod) % Mod; }
long long dp[(1 << (20)) + 5];
long long f[20 + 5][2];
int a[2000000 + 5];
int used[20 + 5];
int tmp[2000000 + 5];
int merge[20][2000000 + 5];
void gao(int l, int r, int p) {
  if (l == r) {
    return;
  }
  gao(l, (l + r) / 2, p + 1);
  gao((l + r) / 2 + 1, r, p + 1);
  int x = (r - l + 1) / 2;
  for (int i = l; i <= (l + r) / 2; i++) {
    tmp[i - l] = a[i];
  }
  sort(tmp, tmp + x);
  for (int i = (l + r) / 2 + 1; i <= r; i++) {
    int cur = (int)(lower_bound(tmp, tmp + x, a[i] + 1) - tmp);
    f[p][0] += x - cur;
  }
  for (int i = (l + r) / 2 + 1; i <= r; i++) {
    tmp[i - ((l + r) / 2 + 1)] = a[i];
  }
  sort(tmp, tmp + x);
  for (int i = l; i <= (l + r) / 2; i++) {
    int cur = (int)(lower_bound(tmp, tmp + x, a[i] + 1) - tmp);
    f[p][1] += x - cur;
  }
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  int N = (1 << (n));
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  gao(0, N - 1, 1);
  int m;
  scanf("%d", &m);
  long long res = 0;
  for (int i = 1; i <= n; i++) res += f[i][0];
  for (int cas = 1; cas <= m; cas++) {
    int q;
    scanf("%d", &q);
    q = n - q;
    for (int i = q + 1; i <= n; i++) {
      if (used[i] == 0) {
        res -= f[i][0];
        res += f[i][1];
      } else {
        res -= f[i][1];
        res += f[i][0];
      }
      used[i] ^= 1;
    }
    printf("%lld\n", res);
  }
  return 0;
}
