#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
  int i;
  for (i = 0; i < rep; i++) p[i] = val;
}
signed long long GETi() {
  signed long long i;
  scanf("%lld", &i);
  return i;
}
int N, M, L;
signed long long A[2000000];
template <class V, int ME>
class BIT {
 public:
  V bit[1 << ME];
  BIT() { clear(); };
  void clear() { memset(bit, 0, sizeof(bit)); };
  V total(int entry) {
    V s = 0;
    entry++;
    while (entry > 0) s += bit[entry - 1], entry -= entry & -entry;
    return s;
  }
  void update(int entry, V val) {
    entry++;
    while (entry <= (1 << ME)) bit[entry - 1] += val, entry += entry & -entry;
  }
};
BIT<int, 21> bt;
signed long long RV[2][20];
void solve() {
  int f, i, j, k, l, x, y;
  cin >> N;
  L = 1 << N;
  map<int, int> MM;
  for (i = 0; i < L; i++) {
    cin >> A[i];
    MM[A[i]] = 0;
  }
  i = 0;
  for (__typeof(MM.begin()) it = MM.begin(); it != MM.end(); it++)
    it->second = ++i;
  for (i = 0; i < L; i++) A[i] = MM[A[i]];
  for (i = 0; i < N; i++) {
    int step = (1 << i);
    bt.clear();
    for (j = 0; j < L; j += step * 2) {
      for (k = 0; k < step; k++) bt.update(A[j + k + step], 1);
      for (k = 0; k < step; k++) RV[0][i] += bt.total(A[j + k] - 1);
      for (k = 0; k < step; k++) bt.update(A[j + k + step], -1);
      for (k = 0; k < step; k++) bt.update(A[j + k], 1);
      for (k = 0; k < step; k++) RV[1][i] += bt.total(A[j + k + step] - 1);
      for (k = 0; k < step; k++) bt.update(A[j + k], -1);
    }
  }
  cin >> M;
  int mask = 0;
  while (M--) {
    cin >> i;
    mask ^= (1 << i) - 1;
    signed long long ret = 0;
    for (i = 0; i < N; i++) ret += RV[(mask >> i) & 1][i];
    (void)printf("%lld\n", ret);
  }
}
int main(int argc, char** argv) {
  string s;
  if (argc == 1) ios::sync_with_stdio(false);
  for (int i = 1; i < argc; i++) s += argv[i], s += '\n';
  for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin);
  solve();
  return 0;
}
