#include <bits/stdc++.h>
using namespace std;
int a[1 << 20];
long long lt[25], gt[25];
void merge(int a[], int d, int s, int t) {
  int i, m, lower_bound, ub;
  if (s == t) return;
  m = (s + t) >> 1;
  merge(a, d - 1, s, m);
  merge(a, d - 1, m + 1, t);
  lower_bound = ub = m + 1;
  for (i = s; i <= m; i++) {
    for (; lower_bound <= t; lower_bound++)
      if (a[lower_bound] >= a[i]) break;
    for (; ub <= t; ub++)
      if (a[ub] > a[i]) break;
    lt[d] += lower_bound - (m + 1);
    gt[d] += t - ub + 1;
  }
  inplace_merge(a + s, a + m + 1, a + t + 1);
}
int main() {
  int i, j, n, m, d;
  long long ans;
  while (scanf("%d", &n) != EOF) {
    ans = 0;
    memset(lt, 0, sizeof(lt));
    memset(gt, 0, sizeof(gt));
    for (i = 0; i < 1 << n; i++) scanf("%d", &a[i]);
    merge(a, n - 1, 0, (1 << n) - 1);
    scanf("%d", &m);
    for (i = 0; i < n; i++) ans += lt[i];
    for (i = 1; i <= m; i++) {
      scanf("%d", &d);
      for (j = 0; j < d; j++) {
        ans = ans - lt[j] + gt[j];
        swap(lt[j], gt[j]);
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
