#include <bits/stdc++.h>
using namespace std;
long long arr[1200000];
long long level[25] = {};
long long total[25] = {};
long long n;
long long findLevel(long long x) {
  long long res = 0;
  while (x > 1) {
    x >>= 1;
    res++;
  }
  return res;
}
long long merge(long long arr[], long long temp[], long long left,
                long long mid, long long right) {
  long long i, j, k;
  long long inv_count = 0;
  i = left;
  j = mid;
  k = left;
  while ((i <= mid - 1) && (j <= right)) {
    if (arr[i] <= arr[j]) {
      temp[k++] = arr[i++];
    } else {
      temp[k++] = arr[j++];
      inv_count = inv_count + (mid - i);
    }
  }
  while (i <= mid - 1) temp[k++] = arr[i++];
  while (j <= right) temp[k++] = arr[j++];
  for (i = left; i <= right; i++) arr[i] = temp[i];
  return inv_count;
}
long long _mergeSort(long long arr[], long long temp[], long long left,
                     long long right) {
  long long mid, inv_count = 0;
  if (right > left) {
    mid = (right + left) / 2;
    inv_count = _mergeSort(arr, temp, left, mid);
    inv_count += _mergeSort(arr, temp, mid + 1, right);
    inv_count += merge(arr, temp, left, mid + 1, right);
  }
  long long l = findLevel(right - left + 1);
  level[n - l] += inv_count;
  if (left == right)
    total[n] = 0;
  else {
    long long acc = 1;
    long long curr = temp[left];
    long long extra = 0;
    for (long long i = left + 1; i <= right; i++) {
      if (temp[i] == curr) {
        acc++;
      } else {
        extra += acc * (acc - 1) / 2;
        acc = 1;
        curr = temp[i];
      }
    }
    extra += acc * (acc - 1) / 2;
    total[n - l] += extra;
  }
  return inv_count;
}
long long invCnt(long long arr[], long long array_size) {
  long long *temp = (long long *)malloc(sizeof(long long) * array_size);
  return _mergeSort(arr, temp, 0, array_size - 1);
}
void solve() {
  cin >> n;
  for (long long((i)) = (0); ((i)) < ((1 << n)); ((i))++) {
    int tmp;
    scanf("%d", &tmp);
    arr[i] = (long long)tmp;
  }
  invCnt(arr, 1 << n);
  long long m;
  cin >> m;
  for (long long((i)) = (0); ((i)) < ((m)); ((i))++) {
    int tmp;
    scanf("%d", &tmp);
    long long q = (long long)tmp;
    long long a = 1 << (n - q);
    long long b = 1 << q;
    long long t = a * (b * (b - 1) / 2);
    long long diff = t - total[n - q] - 2 * level[n - q];
    for (long long i = n - q; i <= n; i++) {
      a = 1 << i;
      b = 1 << (n - i);
      t = a * (b * (b - 1) / 2);
      level[i] = t - total[i] - level[i];
    }
    for (long long i = n - q - 1; i >= 0; i--) {
      level[i] += diff;
    }
    cout << level[0] << endl;
  }
}
int main() {
  solve();
  return 0;
}
