#include <bits/stdc++.h>
using namespace std;
long long st[4 * (1 << 18)];
int swa[20];
int n, q;
void update(int id, int gen, int l, int r, int t, int x) {
  int left = id * 2, right = id * 2 + 1;
  if (swa[gen]) swap(left, right);
  if (t < l || r < t) return;
  if (t == l && l == r) {
    st[id] = x;
    return;
  }
  int m = (l + r) / 2;
  update(left, gen - 1, l, m, t, x);
  update(right, gen - 1, m + 1, r, t, x);
  st[id] = st[left] + st[right];
}
long long ge(int id, int gen, int l, int r, int tl, int tr) {
  int left = id * 2, right = id * 2 + 1;
  if (swa[gen]) swap(left, right);
  if (tr < l || r < tl) return 0;
  if (tl <= l && r <= tr) {
    return st[id];
  }
  int m = (l + r) / 2;
  return ge(left, gen - 1, l, m, tl, tr) + ge(right, gen - 1, m + 1, r, tl, tr);
}
void up(int t, int x) { update(1, n, 1, (1 << n), t, x); }
long long get(int l, int r) { return ge(1, n, 1, (1 << n), l, r); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= (1 << n); ++i) {
    int x;
    cin >> x;
    up(i, x);
  }
  while (q--) {
    int cl, x, t, l, r;
    cin >> cl;
    if (cl == 1) {
      cin >> t >> x;
      up(t, x);
    } else if (cl == 2) {
      cin >> x;
      for (int i = 1; i <= x; ++i) swa[i] ^= 1;
    } else if (cl == 3) {
      cin >> x;
      swa[x + 1] ^= 1;
    } else {
      cin >> l >> r;
      cout << get(l, r) << "\n";
    }
  }
  return 0;
}
