#include <bits/stdc++.h>
using namespace std;
struct seg {
  int k;
  bool rev[19]{};
  long long v = 0;
  seg *ch[2]{};
  seg(int _k) : k(_k) {
    if (k) ch[0] = new seg(k - 1), ch[1] = new seg(k - 1);
  }
  void replace(int l, int r, int i, int d) {
    if (!k) {
      v = d;
      return;
    }
    push();
    int m = l + r >> 1;
    if (i < m)
      ch[0]->replace(l, m, i, d);
    else
      ch[1]->replace(m, r, i, d);
    pull();
  }
  long long query(int l, int r, int _l, int _r) {
    if (_l <= l && r <= _r) return v;
    push();
    long long ans = 0;
    int m = l + r >> 1;
    if (_l < m) ans += ch[0]->query(l, m, _l, _r);
    if (_r > m) ans += ch[1]->query(m, r, _l, _r);
    return ans;
  }
  void pull() { v = ch[0]->v + ch[1]->v; }
  void push() {
    if (rev[k]) swap(ch[0], ch[1]), rev[k] = false;
    for (int i = 0; i < k; ++i)
      ch[0]->rev[i] ^= rev[i], ch[1]->rev[i] ^= rev[i], rev[i] = false;
  }
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, q;
  cin >> n >> q;
  int N = 1 << n;
  seg rt(n);
  for (int i = 0; i < (1 << n); ++i) {
    int x;
    cin >> x;
    rt.replace(0, N, i, x);
  }
  while (q--) {
    int ty, x;
    cin >> ty >> x;
    if (ty == 1) {
      int y;
      cin >> y;
      rt.replace(0, N, x - 1, y);
    } else if (ty == 2)
      for (int i = 1; i <= x; ++i) rt.rev[i] ^= true;
    else if (ty == 3)
      rt.rev[x + 1] ^= true;
    else {
      int y;
      cin >> y;
      cout << rt.query(0, N, x - 1, y) << '\n';
    }
  }
}
