#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
void DBG() { cerr << "]" << '\n'; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << h;
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
struct stree {
  vector<int64> v;
  vector<int> sw;
  stree(int n, int lg) : v(4 * n), sw(lg) {}
  void build(int x, int st, int nd, const vector<int> &a) {
    if (st == nd) {
      v[x] = a[st];
      return;
    }
    int mid = (st + nd) >> 1;
    build(2 * x, st, mid, a);
    build(2 * x + 1, mid + 1, nd, a);
    v[x] = v[2 * x] + v[2 * x + 1];
  }
  void upd(int x, int st, int nd, int p, int k, int lg) {
    if (st > p || nd < p) return;
    if (st == nd) {
      v[x] = k;
      return;
    }
    int mid = (st + nd) >> 1;
    int half = lg - 1;
    if (!sw[half]) {
      upd(2 * x, st, mid, p, k, half);
      upd(2 * x + 1, mid + 1, nd, p, k, half);
    } else {
      upd(2 * x + 1, st, mid, p, k, half);
      upd(2 * x, mid + 1, nd, p, k, half);
    }
    v[x] = v[2 * x] + v[2 * x + 1];
  }
  int64 query(int x, int st, int nd, int a, int b, int lg) {
    if (st > b || nd < a) return 0;
    if (st >= a && nd <= b) return v[x];
    int mid = (st + nd) >> 1;
    int half = lg - 1;
    if (!sw[half])
      return query(2 * x, st, mid, a, b, half) +
             query(2 * x + 1, mid + 1, nd, a, b, half);
    return query(2 * x + 1, st, mid, a, b, half) +
           query(2 * x, mid + 1, nd, a, b, half);
  }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, q;
  cin >> n >> q;
  int m = 1 << n;
  vector<int> a(m);
  for (int i = 0; i < m; i++) cin >> a[i];
  stree st(m, n);
  st.build(1, 0, m - 1, a);
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int x, k;
      cin >> x >> k;
      x--;
      st.upd(1, 0, m - 1, x, k, n);
    } else if (op == 4) {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << st.query(1, 0, m - 1, l, r, n) << '\n';
    } else {
      int x;
      cin >> x;
      if (op == 2)
        for (int i = 0; i < x; i++) st.sw[i] ^= 1;
      else
        st.sw[x] ^= 1;
    }
  }
  return 0;
}
