#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, Mod = 1e9 + 7;
int n, m, q, L, A[N], Xor;
long long SM[N];
long long Get(int l, int r) {
  long long rt = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) rt += SM[l++];
    if (r & 1) rt += SM[--r];
  }
  return rt;
}
inline void Modify(int i, int val) {
  A[i] = val;
  SM[i += n] = val;
  for (; i; i >>= 1) SM[i >> 1] = SM[i] + SM[i ^ 1];
}
inline long long GetF(int r) {
  long long tot = 0;
  while (r > 0) {
    int lg = __builtin_ctz(r);
    r -= r & -r;
    int le = r ^ Xor;
    le &= ((n - 1) - ((1 << lg) - 1));
    tot += Get(le, le + (1 << lg));
  }
  return tot;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> L >> q;
  n = 1 << L;
  for (int i = 0; i < n; i++) cin >> A[i], SM[i + n] = A[i];
  for (int i = n - 1; i; i--) SM[i] = (SM[i << 1] + SM[i << 1 ^ 1]);
  Xor = 0;
  for (; q; q--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int i, val;
      cin >> i >> val;
      i = (i - 1) ^ Xor;
      Modify(i, val);
      continue;
    } else if (tp == 2) {
      int k;
      cin >> k;
      Xor ^= (1 << k) - 1;
      continue;
    } else if (tp == 3) {
      int k;
      cin >> k;
      Xor ^= (1 << k);
    } else {
      int l, r;
      cin >> l >> r;
      long long tot = GetF(r) - GetF(l - 1);
      printf("%lld\n", tot);
    }
  }
  return 0;
}
