#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 { public: vector S; // 少ない方 vector T; // 多い方 int K; 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 { public: vector S; // 少ない方 vector T; // 多い方 int K; int size; JointCal(int size): size(size) { K = sqrt(size); T = vector(size+K, 0); S = vector(size/K+1, 0); } int left(int i) { if (!T[i-1]) return i; i--; while(i >= 0 && T[i]) { int ik = i / K; if (S[ik]) { i = ik*K-1; continue; } i--; } return max((int)0, i+1); } int right(int i) { if (!T[i]) return i; while(T[i]) { int ik = i / K; if (S[ik]) { i = (ik+1)*K; continue; } i++; } return min(i, size-1); } void set(int l, int w) { T[l]=w; int kw = 1; int base = l/K * K; REP(i,K) if (!T[base+i]) kw = 0; S[l / K]=kw; } }; void print(SumCal *A, JointCal *J) { REP(i,N) { cout << A->T[i] << ((J->T[i]) ? '-' : ' '); } cout << endl; } 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: // print(&A, &J); int l = J.left(x); int r = J.right(x); // out("%lld .. %lld = ", l, r); out("%lld\n", A.query(l, r+1)); break; } } //cout << ans << endl; }