#include <bits/stdc++.h>
using namespace std;
int N, n, m, maxLen, threshold, q[1050000];
bool tag[30];
long long lastans, totans, ans[1050005], Ans[2][30];
long long a[1050000], b[1050005];
struct BIT {
  int tree[1050005];
  int lowbit(int x) { return x & (-x); }
  void add(int x, int value) {
    while (x <= N) {
      tree[x] += value;
      x += lowbit(x);
    }
  }
  int query(int x) {
    int ans = 0;
    while (x) {
      ans += tree[x];
      x -= lowbit(x);
    }
    return ans;
  }
} bit_cdq, Pre;
void cdq(int l, int r, int len) {
  maxLen = max(maxLen, len);
  int mid = (l + r) >> 1;
  if (l == r) return;
  cdq(l, mid, len + 1);
  for (int i = l; i <= mid; i++) bit_cdq.add(a[i], 1);
  for (int i = mid + 1; i <= r; i++) {
    Ans[0][len] += bit_cdq.query(a[i] - 1);
    Ans[1][len] += mid - l + 1 - bit_cdq.query(a[i]);
  }
  for (int i = l; i <= mid; i++) bit_cdq.add(a[i], -1);
  cdq(mid + 1, r, len + 1);
}
int main() {
  scanf("%d", &n);
  N = (1 << n);
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", &q[i]);
  for (int i = 1; i <= N; i++) b[i] = a[i];
  sort(b + 1, b + N + 1);
  int cnt = unique(b + 1, b + N + 1) - b - 1;
  for (int i = 1; i <= N; i++) a[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b;
  for (int i = 1; i <= N; i++) {
    lastans += i - 1 - Pre.query(a[i]);
    Pre.add(a[i], 1);
  }
  cdq(1, N, 1);
  for (int i = 1; i <= m; i++) {
    long long nowans = lastans;
    if (q[i] == 0)
      nowans = lastans;
    else {
      for (int j = n - q[i] + 1; j <= maxLen; j++) {
        if (tag[j])
          nowans += Ans[1][j] - Ans[0][j];
        else
          nowans += Ans[0][j] - Ans[1][j];
        tag[j] ^= 1;
      }
      lastans = nowans;
    }
    printf("%lld\n", nowans);
  }
  return 0;
}
