#include <bits/stdc++.h>
using namespace std;
int n, q;
const int N = 262144 + 1;
int a[N];
long long s[N << 2];
int rever[20], swp[20];
void build(int l, int r, int p) {
  if (l == r) {
    s[p] = a[l];
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, p << 1);
  build(mid + 1, r, p << 1 | 1);
  s[p] = s[p << 1] + s[p << 1 | 1];
}
void update(int l, int r, int p, int x, int d, int v) {
  if (l == r) {
    s[p] = v;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    update(l, mid, p << 1 | (rever[d] ^ swp[d - 1]), x, d - 1, v);
  else
    update(mid + 1, r, p << 1 | (rever[d] ^ swp[d - 1] ^ 1), x, d - 1, v);
  s[p] = s[p << 1] + s[p << 1 | 1];
}
long long query(int ql, int qr, int l, int r, int p, int d) {
  if (ql <= l && r <= qr) {
    return s[p];
  }
  int mid = l + r >> 1;
  long long answer = 0;
  if (ql <= mid)
    answer += query(ql, qr, l, mid, p << 1 | (rever[d] ^ swp[d - 1]), d - 1);
  if (qr > mid)
    answer +=
        query(ql, qr, mid + 1, r, p << 1 | (rever[d] ^ swp[d - 1] ^ 1), d - 1);
  return answer;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  int nn = n;
  n = 1 << n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, n, 1);
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int x, y;
      cin >> x >> y;
      update(1, n, 1, x, nn, y);
    }
    if (op == 2) {
      int x;
      cin >> x;
      for (int i = 0; i <= x; i++) rever[i] ^= 1;
    }
    if (op == 3) {
      int x;
      cin >> x;
      swp[x] ^= 1;
    }
    if (op == 4) {
      int l, r;
      cin >> l >> r;
      cout << query(l, r, 1, n, 1, nn) << '\n';
    }
  }
  return 0;
}
