#include <bits/stdc++.h>
using namespace std;
int C[1100000], num[1100000], n, va[1100000];
long long s[25], s2[25];
vector<int> val;
int lowbit(int x) { return x & (-x); }
void add(int pos, int va) {
  num[pos] += va;
  for (int i = pos; i <= (1 << n); i += lowbit(i)) C[i] = C[i] + va;
}
int getsum(int pos) {
  int ans = 0;
  for (int i = pos; i > 0; i -= lowbit(i)) ans = ans + C[i];
  return ans;
}
long long cal(long long x) { return x * (x - 1) / 2; }
void solve(int l, int r, int d) {
  for (int i = l; i < r; i++) {
    s[d] += getsum(va[i] - 1);
    s2[d] += num[va[i]];
    add(va[i], 1);
  }
  for (int i = l; i < r; i++) {
    add(va[i], -1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (1 << n); i++) {
    scanf("%d", &va[i]);
    va[i] = -va[i];
    val.push_back(va[i]);
  }
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  for (int i = 0; i < (1 << n); i++)
    va[i] = lower_bound(val.begin(), val.end(), va[i]) - val.begin() + 1;
  for (int d = 1; d <= n; d++) {
    for (int i = 0; i < (1 << (n - d)); i++) {
      solve(i << d, (i + 1) << d, d);
    }
  }
  int m;
  scanf("%d", &m);
  while (m--) {
    int tem;
    scanf("%d", &tem);
    long long t = cal(1 << tem) * (1 << (n - tem)) - s2[tem] - s[tem];
    long long dif = t - s[tem];
    for (int i = tem; i <= n; i++) {
      s[i] += dif;
    }
    for (int i = 0; i < tem; i++) {
      s[i] = cal(1 << i) * (1 << (n - i)) - s2[i] - s[i];
    }
    printf("%I64d\n", s[n]);
  }
}
