#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int A[1048577], TEMP[1048577];
long long ANS[3][21];
void f(int n, int* Ar) {
  if (n == 0) {
    ANS[0][n] = ANS[1][n] = 0;
    return;
  }
  int sz = (1 << n), s = (sz >> 1);
  f(n - 1, Ar);
  f(n - 1, Ar + s);
  int j = 0;
  for (int i = s; i < sz; ++i) {
    while (Ar[j] < Ar[i] && j < s) j++;
    ANS[1][n] += j;
  }
  j = s;
  for (int i = 0; i < s; ++i) {
    while (Ar[j] < Ar[i] && j < sz) j++;
    ANS[0][n] += (j - s);
  }
  j = s;
  int k = 0;
  for (int i = 0; i < s; ++i) {
    while (Ar[j] <= Ar[i] && j < sz) TEMP[k++] = Ar[j++];
    TEMP[k++] = Ar[i];
  }
  while (j < sz) TEMP[k++] = Ar[j++];
  for (int i = 0; i < sz; ++i) Ar[i] = TEMP[i];
  return;
}
int main() {
  int N;
  memset(ANS, false, sizeof ANS);
  scanf("%d", &N);
  for (int i = 0; i < (1 << N); ++i) scanf("%d", A + i);
  f(N, A);
  int M, x;
  scanf("%d", &M);
  while (M--) {
    scanf("%d", &x);
    ANS[2][x] = 1 - ANS[2][x];
    long long ans = 0;
    int sum = 0;
    for (int i = N; i >= 0; --i) {
      sum += ANS[2][i];
      ans += ANS[sum % 2][i];
    }
    cout << ans << endl;
  }
  return 0;
}
