#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 18) + 5;
long long a[N];
long long o[4 * N];
int dep[30];
void build(int l, int r, int rt) {
  if (l == r) {
    o[rt] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  o[rt] = o[rt << 1] + o[rt << 1 | 1];
}
void change(int l, int r, int rt, int deep, int ops, long long val) {
  if (l == r) {
    o[rt] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (ops <= mid)
    change(l, mid, rt << 1 | dep[deep], deep - 1, ops, val);
  else
    change(mid + 1, r, rt << 1 | dep[deep] ^ 1, deep - 1, ops, val);
  o[rt] = o[rt << 1] + o[rt << 1 | 1];
}
long long sum(int l, int r, int rt, int deep, int ql, int qr) {
  long long res = 0;
  if (l >= ql && r <= qr) {
    return o[rt];
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) res += sum(l, mid, rt << 1 | dep[deep], deep - 1, ql, qr);
  if (qr > mid)
    res += sum(mid + 1, r, rt << 1 | dep[deep] ^ 1, deep - 1, ql, qr);
  return res;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  int n1 = 1 << n;
  for (int i = 1; i <= n1; i++) {
    scanf("%lld", &a[i]);
  }
  build(1, n1, 1);
  for (int i = 1; i <= q; i++) {
    int op, x;
    long long y;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%lld", &x, &y);
      change(1, n1, 1, n, x, y);
    } else if (op == 2) {
      scanf("%d", &x);
      for (int i = 0; i <= x; i++) dep[i] ^= 1;
    } else if (op == 3) {
      scanf("%d", &x);
      dep[x + 1] ^= 1;
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      printf("%lld\n", sum(1, n1, 1, n, l, r));
    }
  }
}
