#include <bits/stdc++.h>
using namespace std;
int n, m, flag[30];
long long sum[400010 << 2], a[400010];
void update(int dep, int now, int l, int r, int p, long long v) {
  if (l == r) {
    sum[now] = v;
    return;
  }
  int mid = (l + r) / 2;
  if (mid >= p) {
    if (flag[dep])
      update(dep - 1, now << 1 | 1, mid + 1, r, p - l + mid + 1, v);
    else
      update(dep - 1, now << 1, l, mid, p, v);
  } else {
    if (flag[dep])
      update(dep - 1, now << 1, l, mid, p - mid - 1 + l, v);
    else
      update(dep - 1, now << 1 | 1, mid + 1, r, p, v);
  }
  sum[now] = sum[now << 1] + sum[now << 1 | 1];
}
long long query(int dep, int now, int l, int r, int L, int R) {
  if (l >= L && r <= R) return sum[now];
  int mid = (l + r) / 2;
  long long res = 0;
  if (flag[dep]) {
    if (mid >= L)
      res += query(dep - 1, now << 1 | 1, mid + 1, r, L - l + mid + 1,
                   min(R, mid) - l + mid + 1);
    if (mid < R)
      res += query(dep - 1, now << 1, l, mid, max(L, mid + 1) - mid - 1 + l,
                   R - mid - 1 + l);
  } else {
    if (mid >= L) res += query(dep - 1, now << 1, l, mid, L, min(R, mid));
    if (mid < R)
      res += query(dep - 1, now << 1 | 1, mid + 1, r, max(L, mid + 1), R);
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (1 << n); i++)
    scanf("%lld", &a[i]), update(n, 1, 1, (1 << n), i, a[i]);
  while (m--) {
    int op, x, y;
    scanf("%d%d", &op, &x);
    if (op == 1) {
      scanf("%d", &y);
      update(n, 1, 1, (1 << n), x, y);
    } else if (op == 2)
      for (int i = x; i >= 0; i--) flag[i] ^= 1;
    else if (op == 3)
      flag[x + 1] ^= 1;
    else {
      scanf("%d", &y);
      printf("%lld\n", query(n, 1, 1, (1 << n), x, y));
    }
  }
  return 0;
}
