#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int L[N], R[N], sp[N], levsp[30], lev[N];
long long val[N], a[N];
void lazyUpdate(int node) {
  if (!L[node]) return;
  if (sp[node] ^ levsp[lev[node]]) {
    swap(L[node], R[node]);
    sp[node] ^= 1;
  }
}
long long build(int node, int l, int r, int lv) {
  if (l == r) return val[node] = a[l];
  int mid = l + r >> 1;
  lev[node] = lv;
  L[node] = node << 1, R[node] = node << 1 | 1;
  val[node] =
      build(L[node], l, mid, lv - 1) + build(R[node], mid + 1, r, lv - 1);
  return val[node];
}
long long update(int node, int l, int r, int pos, int k) {
  lazyUpdate(node);
  if (r < pos || l > pos) return val[node];
  if (l == r) return val[node] = k;
  int mid = l + r >> 1;
  return val[node] = update(L[node], l, mid, pos, k) +
                     update(R[node], mid + 1, r, pos, k);
}
long long query(int node, int l, int r, int pos) {
  lazyUpdate(node);
  if (l > pos) return 0;
  if (r <= pos) return val[node];
  int mid = l + r >> 1;
  return query(L[node], l, mid, pos) + query(R[node], mid + 1, r, pos);
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  int nn = 1 << n;
  for (int i = 1; i <= nn; i++) scanf("%lld", &a[i]);
  build(1, 1, nn, n);
  while (q--) {
    int t, x, k;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d", &x, &k);
      update(1, 1, nn, x, k);
    } else if (t == 2) {
      scanf("%d", &k);
      for (int i = 0; i <= k; i++) levsp[i] ^= 1;
    } else if (t == 3) {
      scanf("%d", &k);
      levsp[k + 1] ^= 1;
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      printf("%lld\n", query(1, 1, nn, r) - query(1, 1, nn, l - 1));
    }
  }
  return 0;
}
