#include <bits/stdc++.h>
using namespace std;
long A[1048576];
long long B[30];
long long C[30];
long P[30];
void f(long n, long o) {
  if (n > 1) {
    f(n - 1, o);
    f(n - 1, o + P[n - 1]);
  }
  sort(A + o, A + o + P[n - 1]);
  sort(A + o + P[n - 1], A + o + P[n]);
  long i = o;
  long j = o + P[n - 1];
  while (i != o + P[n - 1] && j != o + P[n]) {
    if (A[i] < A[j]) {
      B[n] += o + P[n] - j;
      i += 1;
    } else {
      j += 1;
    }
  }
  i = o;
  j = o + P[n - 1];
  while (i != o + P[n - 1] && j != o + P[n]) {
    if (A[i] <= A[j]) {
      i += 1;
    } else {
      C[n] += o + P[n - 1] - i;
      j += 1;
    }
  }
}
int main(int, char**) {
  ios_base::sync_with_stdio(false);
  P[0] = 1;
  for (long i = (1); i <= (29); ++i) P[i] = 2 * P[i - 1];
  long n;
  cin >> n;
  for (long i = 0; i < (P[n]); ++i) cin >> A[i];
  for (long i = 0; i < (29); ++i) B[i] = 0;
  for (long i = 0; i < (29); ++i) C[i] = 0;
  f(n, 0);
  bitset<30> BS;
  long m;
  cin >> m;
  for (long i = 0; i < (m); ++i) {
    long q;
    cin >> q;
    while (q != 0) {
      BS[q] = not BS[q];
      q -= 1;
    }
    long long r = 0;
    for (long j = 0; j < (n + 1); ++j) {
      r += BS[j] ? B[j] : C[j];
    }
    cout << r << "\n";
  }
  return 0;
}
