#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int a[N], msk;
long long st[4 * N];
void build(int l, int r, int p) {
  if (l == r) {
    st[p] = a[l];
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, p * 2);
  build(mid + 1, r, p * 2 + 1);
  st[p] = st[p * 2] + st[p * 2 + 1];
}
void upd(int i, int val, int l, int r, int p, int lvl) {
  if (l == r) {
    st[p] = val;
    return;
  }
  int mid = (l + r) / 2;
  int tar = i <= mid ? 0 : 1;
  bool bit = msk & (1 << lvl);
  tar ^= bit;
  if (i <= mid)
    upd(i, val, l, mid, p * 2 + tar, lvl - 1);
  else
    upd(i, val, mid + 1, r, p * 2 + tar, lvl - 1);
  st[p] = st[p * 2] + st[p * 2 + 1];
}
long long query(int s, int e, int l, int r, int p, int lvl) {
  if (l > e || r < s) return 0;
  if (l >= s && r <= e) return st[p];
  int mid = (l + r) / 2;
  bool bit = msk & (1 << lvl);
  return query(s, e, l, mid, p * 2 + bit, lvl - 1) +
         query(s, e, mid + 1, r, p * 2 + !bit, lvl - 1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, q;
  cin >> n >> q;
  int sz = (1 << n);
  for (int i = 0; i < sz; i++) cin >> a[i];
  build(0, sz - 1, 1);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, k;
      cin >> x >> k;
      x--;
      upd(x, k, 0, sz - 1, 1, n);
    } else if (t == 2) {
      int k;
      cin >> k;
      for (int i = k; i > 0; i--) msk ^= (1 << i);
    } else if (t == 3) {
      int k;
      cin >> k;
      msk ^= (1 << (k + 1));
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << query(l, r, 0, sz - 1, 1, n) << '\n';
    }
  }
}
