#include <bits/stdc++.h>
using namespace std;
int L[2000000];
int R[2000000];
long long tree[2000000];
vector<int> sw[20];
long long a[2000000];
int ls[2000000];
void build(int x, int l, int r) {
  if (l == r)
    tree[x] = a[l];
  else {
    L[x] = x * 2;
    R[x] = x * 2 + 1;
    build(L[x], l, ((l + r) >> 1));
    build(R[x], ((l + r) >> 1) + 1, r);
    tree[x] = tree[L[x]] + tree[R[x]];
  }
}
int T;
long long query(int x, int l, int r, int s, int e, int lev) {
  if (l > e || r < s) return 0;
  if (l >= s && r <= e) return tree[x];
  if (sw[lev].size() && ls[x] != sw[lev].back()) {
    int num =
        sw[lev].end() - upper_bound(sw[lev].begin(), sw[lev].end(), ls[x]);
    num %= 2;
    if (num) swap(L[x], R[x]);
    ls[x] = sw[lev].back();
  }
  return query(L[x], l, ((l + r) >> 1), s, e, lev + 1) +
         query(R[x], ((l + r) >> 1) + 1, r, s, e, lev + 1);
}
void upd(int x, int l, int r, int id, int val, int lev) {
  if (id < l || id > r) return;
  if (l == r)
    tree[x] = val;
  else {
    if (sw[lev].size() && ls[x] != sw[lev].back()) {
      int num =
          sw[lev].end() - upper_bound(sw[lev].begin(), sw[lev].end(), ls[x]);
      num %= 2;
      if (num) swap(L[x], R[x]);
      ls[x] = sw[lev].back();
    }
    if (id <= ((l + r) >> 1))
      upd(L[x], l, ((l + r) >> 1), id, val, lev + 1);
    else
      upd(R[x], ((l + r) >> 1) + 1, r, id, val, lev + 1);
    tree[x] = tree[L[x]] + tree[R[x]];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  int N = n;
  n = (1 << n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  build(1, 0, n - 1);
  while (q--) {
    T++;
    int t;
    cin >> t;
    if (t == 1) {
      int x, k;
      cin >> x >> k;
      x--;
      upd(1, 0, n - 1, x, k, 0);
    } else if (t == 2) {
      int k;
      cin >> k;
      k = N - k;
      for (int i = k; i <= N; i++) sw[i].push_back(T);
    } else if (t == 3) {
      int k;
      cin >> k;
      k = N - k - 1;
      k = max(k, 0);
      sw[k].push_back(T);
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << query(1, 0, n - 1, l, r, 0) << endl;
    }
  }
}
