#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, N;
vector<long long> vec, temp;
long long nr[21][2], py[21];
long long cross, rcross;
void cross_inversion(long long left, long long mid, long long right) {
  long long i = left, j = mid, k = left;
  cross = rcross = 0;
  while ((i <= mid - 1) && (j <= right)) {
    if (vec[i] <= vec[j]) {
      temp[k++] = vec[i++];
    } else {
      temp[k++] = vec[j++];
      cross += (mid - i);
    }
  }
  while (i <= mid - 1) temp[k++] = vec[i++];
  while (j <= right) temp[k++] = vec[j++];
  i = left, j = mid, k = left;
  while ((i <= mid - 1) && (j <= right)) {
    if (vec[j] <= vec[i]) {
      temp[k++] = vec[j++];
    } else {
      temp[k++] = vec[i++];
      rcross += (right + 1 - j);
    }
  }
  for (i = left; i <= right; i++) {
    vec[i] = temp[i];
  }
}
void inversion(long long left, long long right) {
  if (right > left) {
    long long mid = (right + left) >> 1;
    inversion(left, mid);
    inversion(mid + 1, right);
    cross_inversion(left, mid + 1, right);
    long long ht = right - left + 1;
    ht = log2(ht);
    nr[ht][0] += cross, nr[ht][1] += rcross;
  }
}
void solve() {
  cin >> n;
  N = (1 << n);
  vec.resize(N);
  temp.resize(N);
  for (long long i = 0; i < N; i++) {
    cin >> vec[i];
  }
  inversion(0, N - 1);
  long long Q;
  cin >> Q;
  while (Q--) {
    long long p;
    cin >> p;
    for (long long i = 0; i <= p; i++) {
      py[i] ^= 1;
    }
    long long ans = 0;
    for (long long i = 0; i <= n; i++) {
      ans += nr[i][py[i]];
    }
    cout << ans << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
