#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
const long long MOD = 998244353;
long long a[N], sg[4 * N];
int pox;
void build(int v, int tl, int tr) {
  if (tl == tr) {
    sg[v] = a[tl];
    return;
  }
  int tm = (tl + tr) / 2;
  build(v + v, tl, tm);
  build(v + v + 1, tm + 1, tr);
  sg[v] = sg[v + v] + sg[v + v + 1];
}
void update(int v, int tl, int tr, int ind, long long val) {
  if (tl == tr) {
    sg[v] = val;
    return;
  }
  int tm = (tl + tr) / 2;
  if (ind <= tm)
    update(v + v, tl, tm, ind, val);
  else
    update(v + v + 1, tm + 1, tr, ind, val);
  sg[v] = sg[v + v] + sg[v + v + 1];
}
long long query(int v, int tl, int tr, int ind, int tv) {
  if (tl == tr) {
    return sg[v];
  }
  int tm = (tl + tr) / 2;
  if (pox & (1 << tv)) {
    if (ind & (1 << tv)) {
      return sg[v + v + 1] + query(v + v, tl, tm, ind, tv - 1);
    }
    return query(v + v + 1, tm + 1, tr, ind, tv - 1);
  } else {
    if (ind & (1 << tv)) {
      return sg[v + v] + query(v + v + 1, tm + 1, tr, ind, tv - 1);
    }
    return query(v + v, tl, tm, ind, tv - 1);
  }
}
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, q;
  cin >> n >> q;
  int qan = n;
  n = (1 << n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  build(1, 0, n - 1);
  for (int i = 0; i < (q); ++i) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int k, x;
      cin >> k >> x;
      k--;
      k ^= pox;
      update(1, 0, n - 1, k, x);
    }
    if (tp == 2) {
      int k;
      cin >> k;
      pox ^= (1 << k) - 1;
    }
    if (tp == 3) {
      int k;
      cin >> k;
      pox ^= (1 << k);
    }
    if (tp == 4) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      long long ans = query(1, 0, n - 1, r, qan - 1);
      if (l) ans -= query(1, 0, n - 1, l - 1, qan - 1);
      cout << ans << endl;
    }
  }
  return 0;
}
