#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 250005;
int s[20], r[20];
long long sum[maxn << 2];
int lay;
int n;
void pushup(int x) { sum[x] = sum[x << 1] + sum[x << 1 | 1]; }
void build(int x, int l, int r) {
  if (l == r) {
    cin >> sum[x];
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
void update(int x, int l, int r, int p, int del) {
  if (l == r) {
    sum[x] = del;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid) {
    update(x << 1, l, mid, p, del);
  } else {
    update(x << 1 | 1, mid + 1, r, p, del);
  }
  pushup(x);
}
long long query(int x, int l, int r, int ql, int qr) {
  if (ql <= l && qr >= r) {
    return sum[x];
  }
  long long ret = 0;
  int mid = (l + r) >> 1;
  if (ql <= mid) {
    ret += query(x << 1, l, mid, ql, qr);
  }
  if (qr > mid) {
    ret += query(x << 1 | 1, mid + 1, r, ql, qr);
  }
  return ret;
}
int revfind(int x) {
  for (int i = lay; i >= 0; i--) {
    if (s[i]) {
      int m = (1 << i);
      int blk = x / m;
      int md = x % m;
      x = (blk ^ 1) * m + md;
    }
    if (r[i]) {
      int m = (1 << i);
      int blk = x / m;
      int md = x % m;
      x = (blk)*m + m - 1 - md;
    }
  }
  return x;
}
long long solve(int x) {
  if (x == -1) {
    return 0;
  }
  int tot = x + 1;
  int sm = 0;
  long long ret = 0;
  for (int i = lay; i >= 0; i--) {
    if (tot & (1 << i)) {
      int st = sm;
      int idx1 = revfind(st);
      idx1 /= (1 << i);
      idx1 *= (1 << i);
      ret += query(1, 0, n, idx1, idx1 + (1 << i) - 1);
      sm += (1 << i);
    }
  }
  return ret;
}
void go() {
  int m;
  cin >> n >> m;
  lay = n;
  n = (1 << n) - 1;
  build(1, 0, n);
  for (int i = 0; i < m; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      int x, k;
      cin >> x >> k;
      x--;
      x = revfind(x);
      update(1, 0, n, x, k);
    } else if (op == 2) {
      int x;
      cin >> x;
      r[x] ^= 1;
    } else if (op == 3) {
      int x;
      cin >> x;
      s[x] ^= 1;
    } else if (op == 4) {
      int l, r;
      cin >> l >> r;
      l--, r--;
      cout << solve(r) - solve(l - 1) << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int c = 0;
  int t;
  if (!c) {
    t = 1;
  } else {
    cin >> t;
  }
  while (t--) {
    go();
  }
}
