#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long sm;
  long long cnt_sw;
  long long depth;
  Node *l, *r;
  Node(long long val_)
      : sm(val_), depth(0), cnt_sw(0), l(nullptr), r(nullptr) {}
};
const long long MAXN = 19;
long long a[(1 << MAXN)], swap_cnt[MAXN];
void build(Node *&root, long long l, long long r, long long dep = 0) {
  if (l + 1 == r) {
    root = new Node(a[l]);
    root->depth = dep;
    return;
  }
  root = new Node(0);
  root->depth = dep;
  long long m = (l + r) / 2;
  build(root->l, l, m, dep + 1);
  build(root->r, m, r, dep + 1);
  root->sm = root->l->sm + root->r->sm;
}
void push(Node *root) {
  if (swap_cnt[root->depth] % 2 != root->cnt_sw % 2) {
    swap(root->l, root->r);
    root->cnt_sw++;
  }
}
void change(Node *root, long long l, long long r, long long pos, long long x) {
  push(root);
  if (l + 1 == r) {
    root->sm = x;
    return;
  }
  long long m = (l + r) / 2;
  if (pos < m) {
    change(root->l, l, m, pos, x);
  } else {
    change(root->r, m, r, pos, x);
  }
  root->sm = root->l->sm + root->r->sm;
}
long long get_sm(Node *root, long long l, long long r, long long ql,
                 long long qr) {
  push(root);
  if (l == ql && r == qr) {
    return root->sm;
  }
  long long m = (l + r) / 2;
  if (qr <= m) {
    return get_sm(root->l, l, m, ql, qr);
  }
  if (ql >= m) {
    return get_sm(root->r, m, r, ql, qr);
  }
  return get_sm(root->l, l, m, ql, m) + get_sm(root->r, m, r, m, qr);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, q;
  cin >> n >> q;
  for (long long i = 0; i < (1 << n); i++) {
    cin >> a[i];
  }
  Node *root = nullptr;
  build(root, 0, 1 << n);
  long long x, k, l, r;
  while (q--) {
    long long op;
    cin >> op;
    if (op == 1) {
      cin >> x >> k;
      change(root, 0, 1 << n, x - 1, k);
    } else if (op == 2) {
      cin >> k;
      k = n - k;
      for (long long i = k; i <= n; i++) {
        swap_cnt[i]++;
      }
    } else if (op == 3) {
      cin >> k;
      swap_cnt[n - k - 1]++;
    } else {
      cin >> l >> r;
      cout << get_sm(root, 0, 1 << n, l - 1, r) << '\n';
    }
  }
}
