#include <bits/stdc++.h>
using namespace std;
int MID[8000001], be[2000005], sum[8000001][2];
long long f[10001][2], ans;
int n, i, N, x, t, j, k, m, key[10001], q;
struct rec {
  int x, id;
} E[2000005];
bool cmp(rec a, rec b) { return a.x < b.x; }
void build(int t, int l, int r) {
  MID[t] = (l + r) >> 1;
  if (l == r) {
    be[l] = t;
    return;
  }
  int mid = (l + r) >> 1;
  build(t * 2, l, mid);
  build(t * 2 + 1, mid + 1, r);
}
int main() {
  scanf("%d", &n);
  N = 1;
  for (i = 1; i <= n; i++) N *= 2;
  build(1, 1, N);
  for (i = 1; i <= N; i++) {
    scanf("%d", &E[i].x);
    E[i].id = i;
  }
  sort(E + 1, E + 1 + N, cmp);
  for (i = 1; i <= N; i = k) {
    for (k = i; E[k].x == E[i].x && k <= N; k++) {
      x = E[k].id;
      t = be[x];
      j = 0;
      while (t) {
        if (x > MID[t])
          f[j][1] += sum[t][1];
        else
          f[j][0] += sum[t][0];
        t >>= 1;
        j++;
      }
    }
    for (k = i; E[k].x == E[i].x && k <= N; k++) {
      x = E[k].id;
      t = be[x];
      j = 0;
      while (t) {
        if (x > MID[t])
          sum[t][0]++;
        else
          sum[t][1]++;
        t >>= 1;
        j++;
      }
    }
  }
  for (i = 1; i <= n; i++) ans += f[i][0];
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &q);
    for (; q; q--) {
      ans -= f[q][key[q]] - f[q][key[q] ^ 1];
      key[q] ^= 1;
    }
    printf("%I64d\n", ans);
  }
}
