#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 1000005;
const int INF = (int)2e9;
int P, N, M, A[1 << 20 + 5], state[21];
long long cont[21][2];
vector<int> combine(const vector<int>& A, const vector<int>& B,
                    long long& inv) {
  vector<int> vec;
  int a = 0, b = 0;
  while (a < ((int)A.size()) && b < ((int)B.size())) {
    while (a < ((int)A.size()) && A[a] <= B[b]) vec.push_back(A[a++]);
    if (a == ((int)A.size())) break;
    while (b < ((int)B.size()) && A[a] > B[b]) {
      inv += ((int)A.size()) - a;
      vec.push_back(B[b]);
      ++b;
    }
  }
  while (a < ((int)A.size())) vec.push_back(A[a++]);
  while (b < ((int)B.size())) vec.push_back(B[b++]);
  return vec;
}
vector<int> build(int l, int r, int p) {
  long long len = r - l + 1;
  vector<int> vec;
  if (l == r) {
    vec.push_back(A[l]);
  } else {
    int m = (l + r) / 2;
    vector<int> lval = build(l, m, p - 1);
    vector<int> rval = build(m + 1, r, p - 1);
    vec = combine(lval, rval, cont[p][0]);
    vec = combine(rval, lval, cont[p][1]);
  }
  return vec;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> P;
  N = (1 << P);
  for (int i = 0; i < N; ++i) cin >> A[i];
  build(0, N - 1, P);
  cin >> M;
  for (int _ = 0; _ < M; ++_) {
    int q;
    cin >> q;
    state[q] ^= 1;
    long long ans = 0;
    int p = 0;
    for (int i = P; i >= int(0); --i) {
      p ^= state[i];
      ans += cont[i][p];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
