#include <bits/stdc++.h>
using namespace std;
long long LLMAX = 9223372036854775807LL;
const int MOD = 1000000007;
const int maxn = 100000 + 10;
long long gt[111], lt[111];
int n, m;
int a[1 << 21];
void solve(int d, int s, int t) {
  if (t - s == 1) return;
  int u = (s + t) / 2;
  solve(d - 1, s, u);
  solve(d - 1, u, t);
  int lb = u, ub = u;
  for (int i = s; i < u; ++i) {
    for (; lb < t; ++lb)
      if (a[lb] >= a[i]) break;
    for (; ub < t; ++ub)
      if (a[ub] > a[i]) break;
    lt[d] += lb - u;
    gt[d] += t - ub;
  }
  inplace_merge(a + s, a + u, a + t);
}
int main() {
  scanf("%d", &(n));
  for (int i = 0; i < (1 << n); ++i) scanf("%d", &(a[i]));
  solve(n - 1, 0, 1 << n);
  scanf("%d", &(m));
  int q;
  long long now = 0;
  for (int i = 0; i < n; ++i) now += lt[i];
  while (m--) {
    scanf("%d", &(q));
    for (int i = 0; i < q; ++i) {
      now = now - lt[i] + gt[i];
      swap(lt[i], gt[i]);
    }
    printf("%I64d\n", now);
  }
}
