#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int maxn = (1 << 18) + 3;
int a[maxn];
int n, q;
void read() {
  cin >> n >> q;
  for (int i = 1; i <= (1 << n); i++) cin >> a[i];
}
struct node {
  long long sum;
  int l, r;
  bool rev, to_swap;
};
node tr[maxn * 4];
bool rev[20], to_swap[20];
void merge(int v) { tr[v].sum = tr[tr[v].l].sum + tr[tr[v].r].sum; }
void push(int v, int lvl) {
  if (lvl == n) return;
  tr[v].rev ^= rev[lvl];
  if (tr[v].rev) {
    swap(tr[tr[v].l], tr[tr[v].r]);
    tr[tr[v].l].rev ^= 1;
    tr[tr[v].r].rev ^= 1;
  }
  tr[v].rev = rev[lvl];
  tr[v].to_swap ^= to_swap[lvl];
  if (tr[v].to_swap) swap(tr[tr[v].l], tr[tr[v].r]);
  tr[v].to_swap = to_swap[lvl];
}
void build(int v, int l, int r) {
  if (l == r) {
    tr[v] = {a[l], 0, 0, false, false};
    return;
  }
  tr[v] = {0, v * 2, v * 2 + 1, false, false};
  int mid = (l + r) / 2;
  build(v * 2, l, mid);
  build(v * 2 + 1, mid + 1, r);
  merge(v);
}
void update(int v, int l, int r, int pos, int val, int lvl) {
  push(v, lvl);
  if (l == r) {
    tr[v].sum = val;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    update(tr[v].l, l, mid, pos, val, lvl + 1);
  else
    update(tr[v].r, mid + 1, r, pos, val, lvl + 1);
  merge(v);
}
long long get(int v, int l, int r, int ll, int rr, int lvl) {
  push(v, lvl);
  if (l > rr || r < ll) return 0;
  if (l >= ll && r <= rr) return tr[v].sum;
  int mid = (l + r) / 2;
  return get(tr[v].l, l, mid, ll, rr, lvl + 1) +
         get(tr[v].r, mid + 1, r, ll, rr, lvl + 1);
}
void solve() {
  build(1, 1, (1 << n));
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, val;
      cin >> pos >> val;
      update(1, 1, (1 << n), pos, val, 0);
    } else if (type == 2) {
      int k;
      cin >> k;
      rev[n - k] ^= 1;
    } else if (type == 3) {
      int k;
      cin >> k;
      to_swap[n - k - 1] ^= 1;
    } else {
      int l, r;
      cin >> l >> r;
      cout << get(1, 1, (1 << n), l, r, 0) << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
