#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int size;
  cin >> size;
  vector<int> numbers(1 << size);
  for (int _n((1 << size)), i(0); i < _n; i++) cin >> numbers[i];
  vector<long long> more(size, 0), less(size, 0);
  vector<int> state(size, 0);
  vector<int> next(1 << size);
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < (1 << size); j += 1 << (i + 1)) {
      int middle = j + (1 << i);
      int end = middle + (1 << i);
      int at1 = j;
      int at2 = middle;
      int at = j;
      while (at1 < middle && at2 < end) {
        if (numbers[at1] <= numbers[at2]) {
          next[at++] = numbers[at1++];
          more[i] += at2 - middle;
        } else {
          next[at++] = numbers[at2++];
        }
      }
      while (at1 < middle) {
        next[at++] = numbers[at1++];
        more[i] += 1 << i;
      }
      while (at2 < end) {
        next[at++] = numbers[at2++];
      }
      at1 = j;
      at2 = middle;
      at = j;
      while (at1 < middle && at2 < end) {
        if (numbers[at1] < numbers[at2]) {
          next[at++] = numbers[at1++];
        } else {
          next[at++] = numbers[at2++];
          less[i] += at1 - j;
        }
      }
      while (at1 < middle) {
        next[at++] = numbers[at1++];
      }
      while (at2 < end) {
        next[at++] = numbers[at2++];
        less[i] += 1 << i;
      }
    }
    next.swap(numbers);
  }
  long long answer = accumulate(more.begin(), more.end(), 0ll);
  int queryCount;
  cin >> queryCount;
  for (int i = 0; i < queryCount; i++) {
    int query;
    cin >> query;
    for (int j = 0; j < query; j++) {
      if (state[j]) {
        answer += more[j];
        answer -= less[j];
      } else {
        answer += less[j];
        answer -= more[j];
      }
      state[j] ^= true;
    }
    cout << answer << endl;
  }
  return 0;
}
