#include using namespace std; #define rep(i, n) for (int i = 0, _##i = (n); i < _##i; ++i) struct BIT { vector data; BIT() {} BIT(int N) : data(N + 1) { fill(data.begin(), data.end(), 0); data[0] = N; } void add(int pos, int val) { while (pos <= data[0]) { data[pos] += val; pos += pos & -pos; } } int sum(int pos) { if (pos <= 0) return 0; int res = 0; while (pos > 0) { res += data[pos]; pos -= pos & -pos; } return res; } int lower_bound(int val) { if (val <= 0) return 0; int index = 0; for (int d = 1 << int(log2(data[0])); d > 0; d /= 2) { if (index + d <= data[0] && data[index + d] < val) { val -= data[index + d]; index += d; } } return index; } }; struct GCT { int size; BIT bit; GCT(int N) : bit(N), size(N) { for (int i = 1; i <= bit.data[0]; i++) { bit.data[i] = i & -i; } } int group_index(int index) { return bit.sum(index + 1) - 1; } int dist(int x, int y) { return abs(group_index(x) - group_index(y)); } int begin(int group_index) { return bit.lower_bound(group_index + 1); } int end(int group_index) { return bit.lower_bound(group_index + 2); } int group_size(int group_index) { return end(group_index) - begin(group_index); } void group(int index) { int s = -(bit.sum(index + 2) - bit.sum(index + 1)); bit.add(index + 2, s); size += s; } void cut(int index) { int s = !(bit.sum(index + 2) - bit.sum(index + 1)); bit.add(index + 2, s); size += s; } }; int main() { int N, Q; cin >> N >> Q; int A, B; BIT bit(N); GCT gct(N); rep(i, N) cin >> A, bit.add(i + 1, A); rep(i, Q) { cin >> A >> B; if (A == 1) { gct.group(B - 1); } else if (A == 2) { gct.cut(B - 1); } else if (A == 3) { bit.add(B, 1); } else { int index = gct.group_index(B - 1); cout << bit.sum(gct.end(index)) - bit.sum(gct.begin(index)) << endl; } } }