#include <bits/stdc++.h>
const int maxn = 3e5 + 1;
inline long long max(long long a, long long b) { return a > b ? a : b; }
inline long long min(long long a, long long b) { return a < b ? a : b; }
long long rev[19], n, m, opt, k, x, l, r;
struct Segment_Tree {
  long long val[maxn << 2];
  inline void pushup(long long rt) {
    val[rt] = val[rt << 1] + val[rt << 1 | 1];
  }
  inline void build(long long rt, long long l, long long r) {
    if (l == r) return (void)(scanf("%lld", &val[rt]));
    build(rt << 1, l, ((l + r) >> 1));
    build(rt << 1 | 1, ((l + r) >> 1) + 1, r);
    pushup(rt);
  }
  inline void update(long long rt, long long l, long long r, long long k,
                     long long ch, long long dep) {
    if (l == r) return (void)(val[rt] = ch);
    if (k > ((l + r) >> 1)) {
      if (rev[dep])
        update(rt << 1, ((l + r) >> 1) + 1, r, k, ch, dep - 1);
      else
        update(rt << 1 | 1, ((l + r) >> 1) + 1, r, k, ch, dep - 1);
    } else {
      if (rev[dep])
        update(rt << 1 | 1, l, ((l + r) >> 1), k, ch, dep - 1);
      else
        update(rt << 1, l, ((l + r) >> 1), k, ch, dep - 1);
    }
    pushup(rt);
  }
  inline long long query(long long rt, long long l, long long r, long long L,
                         long long R, long long dep) {
    if (L <= l && r <= R) return val[rt];
    long long ans = 0;
    if (L <= ((l + r) >> 1)) {
      if (rev[dep])
        ans += query(rt << 1 | 1, l, ((l + r) >> 1), L, R, dep - 1);
      else
        ans += query(rt << 1, l, ((l + r) >> 1), L, R, dep - 1);
    }
    if (R > ((l + r) >> 1)) {
      if (rev[dep])
        ans += query(rt << 1, ((l + r) >> 1) + 1, r, L, R, dep - 1);
      else
        ans += query(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, dep - 1);
    }
    return ans;
  }
} t;
signed main() {
  scanf("%lld %lld", &n, &m);
  t.build(1, 1, (1ll << n));
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", &opt);
    if (opt == 1)
      scanf("%lld %lld", &x, &k), t.update(1, 1, (1ll << n), x, k, n);
    if (opt == 2) {
      scanf("%lld", &k);
      for (long long yny = 0; yny <= k; yny++) rev[yny] ^= 1;
    }
    if (opt == 3) scanf("%lld", &k), rev[k + 1] ^= 1;
    if (opt == 4)
      scanf("%lld %lld", &l, &r),
          printf("%lld\n", t.query(1, 1, (1ll << n), l, r, n));
  }
}
