#include <bits/stdc++.h>
using namespace std;
long long N, P, Q, resp;
long long a[1500005];
long long b[1500005];
long long tmp[1500005];
long long inv[25][2];
bool is[25];
void cntInv2(long long l, long long r, long long p) {
  if (p == 0) return;
  long long ans = 0;
  long long mid = (l + r) / 2;
  cntInv2(l, mid, p - 1);
  cntInv2(mid + 1, r, p - 1);
  long long id1 = mid;
  long long id2 = r;
  long long idx = r;
  while (idx >= l) {
    if (id1 < l)
      b[idx--] = a[id2--];
    else if (id2 < mid + 1)
      b[idx--] = a[id1--];
    else if (a[id2] <= a[id1])
      b[idx--] = a[id2--];
    else {
      ans += id2 - mid;
      b[idx--] = a[id1--];
    }
  }
  for (long long i = l; i <= r; i++) a[i] = b[i];
  inv[p][1] += ans;
}
void cntInv1(long long l, long long r, long long p) {
  if (p == 0) return;
  long long ans = 0;
  long long mid = (l + r) / 2;
  cntInv1(l, mid, p - 1);
  cntInv1(mid + 1, r, p - 1);
  long long id1 = l;
  long long id2 = mid + 1;
  long long idx = l;
  while (idx <= r) {
    if (id1 > mid)
      b[idx++] = a[id2++];
    else if (id2 > r)
      b[idx++] = a[id1++];
    else if (a[id1] <= a[id2])
      b[idx++] = a[id1++];
    else {
      ans += mid - id1 + 1;
      b[idx++] = a[id2++];
    }
  }
  for (long long i = l; i <= r; i++) a[i] = b[i];
  inv[p][0] += ans;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> P;
  N = (1 << P);
  for (long long i = 1; i <= N; i++) cin >> tmp[i];
  for (long long i = 1; i <= N; i++) a[i] = tmp[i];
  cntInv1(1, N, P);
  for (long long i = 1; i <= N; i++) a[i] = tmp[i];
  cntInv2(1, N, P);
  for (long long i = 1; i <= P; i++) resp += inv[i][0];
  cin >> Q;
  while (Q--) {
    long long p;
    cin >> p;
    for (long long i = p; i >= 0; i--) {
      resp -= inv[i][is[i]];
      is[i] = !is[i];
      resp += inv[i][is[i]];
    }
    cout << resp << "\n";
  }
  return 0;
}
