#include "bits/stdc++.h" using namespace std; #define int long long #define FOR(i, a, b) for(int i=(a);i<(b);i++) #define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--) #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) #define ALL(a) (a).begin(),(a).end() #define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end()); #define CONTAIN(a, b) find(ALL(a), (b)) != (a).end() #define array2(type, x, y) array, x> #define vector2(type) vector > #define out(...) printf(__VA_ARGS__) int dxy[] = {0, 1, 0, -1, 0}; void solve(); signed main() { #if DEBUG std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; } /*================================*/ int N,M,Q; /******************************** * * 平方分割 * *******************************/ class SumCal { vector S; // 少ない方 vector T; // 多い方 int K; public: SumCal(int size) { K = sqrt(size); T = vector(size, 0); S = vector(size/K+1, 0); } int query(int l, int r) { int ret = 0; while(l < r) { int lk = l / K; int rk = r / K; if (lk == rk) { FOR(j, l, r) { ret += T[j]; } } else if (l % K == 0) { ret += S[lk]; } else { FOR(j, l, (lk+1)*K) { ret += T[j]; } } l = (lk+1)*K; } return ret; } void add(int l, int w) { T[l]+=w; S[l/K]+=w; } }; /******************************** * * 平方分割 * *******************************/ class JointCal { vector S; // 少ない方 vector T; // 多い方 int K; int size; public: JointCal(int size): size(size) { K = sqrt(size); T = vector(size, 0); S = vector(size/K+1, 0); } int left(int i) { i--; if (!T[i]) return i+1; while(i >= 0 && T[i]) { int ik = i / K; if (S[ik]) { if (ik == 0) return 0; i = (ik-1)*K; continue; } i--; } return i+1; } int right(int i) { if (!T[i]) return i; while(T[i]) { int ik = i / K; if (S[ik]) { if (ik == S.size()-1) return size-1; i = (ik+1)*K; continue; } i++; } return i; } void set(int l, int w) { T[l]=w; int kw = 1; int base = l/K * K; REP(i,K) kw &= T[base+i]; S[l / K]=kw; } }; void solve() { cin>>N>>Q; int a; auto A = SumCal(N); // かっこよさ auto J = JointCal(N); // Joint REP(i,N) { cin>>a; A.add(i, a); } int q,x; REP(i,Q) { cin>>q>>x; x--; switch (q) { case 1: J.set(x, 1); break; case 2: J.set(x, 0); break; case 3: A.add(x, 1); break; default: int l = J.left(x); int r = J.right(x); // out("%lld x %lld = ", l, r); out("%lld\n", A.query(l, r+1)); break; } } //cout << ans << endl; }