#include <bits/stdc++.h>
using namespace std;
int tp, q, N;
vector<int> swapped(20);
class SegmentTree {
 private:
  vector<long long> tree;
  vector<long long> raw;
  int n;
  vector<vector<int> > ep;
  long long bound = 0;
  long long merge(long long a, long long b) { return a + b; }
  void buildTree(int l, int r, int p, int k) {
    if (l == r) {
      tree[p] = raw[l];
      return;
    }
    int mid = (l + r) / 2;
    int c1 = 2 * p + 1, c2 = 2 * p + 2;
    ep[c1] = {l, mid};
    ep[c2] = {mid + 1, r};
    buildTree(l, mid, c1, k - 1);
    buildTree(mid + 1, r, c2, k - 1);
    tree[p] = merge(tree[c1], tree[c2]);
  }
  void update(int i, long long val, int l, int r, int p, int k) {
    if (l > i or r < i) return;
    if (l == r) {
      tree[p] = val;
      return;
    }
    int mid = (l + r) / 2;
    int c1 = 2 * p + 1, c2 = 2 * p + 2;
    if (swapped[k]) swap(c1, c2);
    update(i, val, l, mid, c1, k - 1);
    update(i, val, mid + 1, r, c2, k - 1);
    tree[p] = merge(tree[c1], tree[c2]);
  }
  long long sum(int i, int j, int l, int r, int p, int k) {
    if (l > j or r < i) return bound;
    if (l >= i and r <= j) return tree[p];
    int mid = (l + r) / 2;
    int c1 = 2 * p + 1, c2 = 2 * p + 2;
    if (swapped[k]) swap(c1, c2);
    return merge(sum(i, j, l, mid, c1, k - 1),
                 sum(i, j, mid + 1, r, c2, k - 1));
  }

 public:
  SegmentTree(vector<long long> input) {
    raw = input;
    n = raw.size();
    tree.resize(4 * n);
    ep.resize(4 * n, vector<int>(2));
    ep[0] = {0, n - 1};
    buildTree(0, n - 1, 0, tp);
  }
  long long sum(int i, int j) { return sum(i, j, 0, n - 1, 0, tp); }
  void update(int i, long long val) { update(i, val, 0, n - 1, 0, tp); }
  void treeSwap(int k) {
    k += 1;
    swapped[k] = 1 - swapped[k];
  }
  void rev(int k) {
    for (int i = 0; i < (int)k; i++) treeSwap(i);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> tp >> q;
  N = 1 << tp;
  vector<long long> nums(N);
  for (int i = 0; i < (int)N; i++) cin >> nums[i];
  SegmentTree tree(nums);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      long long x, k;
      cin >> x >> k;
      tree.update(x - 1, k);
    } else if (t == 2) {
      int k;
      cin >> k;
      tree.rev(k);
    } else if (t == 3) {
      int k;
      cin >> k;
      tree.treeSwap(k);
    } else {
      int l, r;
      cin >> l >> r;
      cout << tree.sum(l - 1, r - 1) << '\n';
    }
  }
  return 0;
}
