#include #include using namespace std; using ll = long long int; template struct FenwickTree{ const int n; vector arr; FenwickTree() = default; FenwickTree(int n): n(n), arr(vector(n+1, 0)){} void add(int ind, T x){ for(int i = ind+1; i <= n; i += i & (-i)){ arr[i] += x; } } // [0, end) T sum_sub(int end){ T res = 0; for(int i = end; i > 0; i -= i & (-i)){ res += arr[i]; } return res; } // [start, end) T sum(int start, int end){ return sum_sub(end) - sum_sub(start); } int lower_bound(T w){ if(w <= 0) return 0; int x = 0; int k = 1 << 30; while(k > n) k /= 2; for(; k > 0; k /= 2){ if(x+k <= n && arr[x+k] < w){ w -= arr[x+k]; x += k; } } return x; } }; int main(){ int n, q; cin >> n >> q; vector a(n); for(auto &it: a) cin >> it; FenwickTree sum(n); for(int i = 0; i < n; i++) sum.add(i, a[i]); FenwickTree range(n); for(int i = 1; i < n; i++) range.add(i, 1); while(q--){ int op, x; cin >> op >> x; --x; if(op == 1){ if(range.sum(x+1, x+2) == 1) range.add(x+1, -1); }else if(op == 2){ if(range.sum(x+1, x+2) == 0) range.add(x+1, 1); }else if(op == 3){ sum.add(x, 1); }else{ // cout << range.sum(0, 1) << " " << range.sum(1, 2) << " "; int r = range.lower_bound(range.sum(0, x+1)+1); int l = range.lower_bound(range.sum(0, x+1)); // cout << l << " " << r << " "; cout << sum.sum(l, r) << '\n'; } } return 0; }