#include <bits/stdc++.h>
using namespace std;
int n, q;
int mask;
int All[19];
long long arr[1 << 18];
long long SegTree[(1 << 19) | 5];
void Update(int pos, long long val) {
  for (pos = pos + (1 << n); pos > 0; pos >>= 1) {
    SegTree[pos] += val;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  All[0] = 0;
  for (int i = 1; i <= n; i++) {
    All[i] = (All[i - 1] << 1) | 1;
  }
  for (int i = 0; i < 1 << n; i++) {
    cin >> arr[i];
    Update(i, arr[i]);
  }
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, val;
      cin >> pos >> val;
      --pos;
      pos ^= mask;
      Update(pos, val - arr[pos]);
      arr[pos] = val;
    } else if (type == 2) {
      int k;
      cin >> k;
      mask ^= ((1 << k) - 1);
    } else if (type == 3) {
      int k;
      cin >> k;
      mask ^= (1 << k);
    } else {
      int l, r;
      long long ans = 0;
      cin >> l >> r;
      --l;
      --r;
      while (l <= r) {
        for (int sz = n; sz >= 0; sz--) {
          if (!(l & All[sz])) {
            if (l + (1 << sz) - 1 <= r) {
              int realmask = mask >> sz, reall = l >> sz;
              reall ^= realmask;
              ans += SegTree[reall + (1 << (n - sz))];
              l += (1 << sz);
              break;
            }
          }
        }
      }
      cout << ans << '\n';
    }
  }
}
