#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
int read() {
  int x;
  scanf(" %d", &x);
  return x;
}
const int N = 1 << 18;
ll a[2 * N];
int state[20];
ll findsum(int k, int u, int l, int r, int x1, int x2) {
  if (l > x2 || r < x1) {
    return 0;
  }
  if (l >= x1 && r <= x2) {
    return a[u];
  }
  int m = (l + r) / 2;
  if (!state[k]) {
    return findsum(k - 1, u + u, l, m, x1, x2) +
           findsum(k - 1, u + u + 1, m + 1, r, x1, x2);
  } else {
    return findsum(k - 1, u + u, m + 1, r, x1, x2) +
           findsum(k - 1, u + u + 1, l, m, x1, x2);
  }
}
void update(int k, int u, int l, int r, int x, int v) {
  if (l > x || r < x) {
    return;
  }
  if (l == r) {
    a[u] = v;
    return;
  }
  int m = (l + r) / 2;
  if (!state[k]) {
    update(k - 1, u + u, l, m, x, v);
    update(k - 1, u + u + 1, m + 1, r, x, v);
  } else {
    update(k - 1, u + u, m + 1, r, x, v);
    update(k - 1, u + u + 1, l, m, x, v);
  }
  a[u] = a[u + u] + a[u + u + 1];
}
int main() {
  int n = read();
  int q = read();
  int m = 1 << n;
  for (int i = 0; i < m; i++) {
    a[i + m] = read();
  }
  for (int i = m - 1; i > 0; i--) {
    a[i] = a[i + i] + a[i + i + 1];
  }
  while (q--) {
    int t = read();
    if (t == 1) {
      int x = read() - 1;
      int k = read();
      update(n, 1, 0, m - 1, x, k);
    } else if (t == 2) {
      int k = read();
      for (int i = 1; i <= k; i++) {
        state[i] ^= 1;
      }
    } else if (t == 3) {
      int k = read();
      state[k + 1] ^= 1;
    } else if (t == 4) {
      int l = read() - 1;
      int r = read() - 1;
      printf("%lld\n", findsum(n, 1, 0, m - 1, l, r));
    }
  }
  return 0;
}
