#include using namespace std; typedef long long int ll; typedef pair P; #define repi(i,a,b) for(ll i=a;i=0;i--) //debug #define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr< struct SegmentTree { using F = function< Monoid(Monoid, Monoid) >; ll sz; vector< Monoid > seg; const F f; const Monoid M1; SegmentTree(ll n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while(sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(ll k, const Monoid &x) { seg[k + sz] = x; } void build() { for(ll k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(ll k, const Monoid &x) { k += sz; seg[k] = x; while(k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(ll a, ll b) { Monoid L = M1, R = M1; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) L = f(L, seg[a++]); if(b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const ll &k) const { return seg[k + sz]; } }; ll f(ll a, ll b){ return a + b; } int main(){ ll N, Q; cin >> N >> Q; SegmentTree seg(N, f, 0); rep(i, N){ ll a; cin >> a; seg.set(i, a); } seg.build(); set beginning; rep(i, N+1) beginning.insert(i); rep(_, Q){ ll q, x; cin >> q >> x; if(q == 1){ beginning.erase(x); } else if(q == 2){ beginning.insert(x); } else if(q == 3){ seg.update(x-1, seg[x-1] + 1); } else{ auto it = beginning.upper_bound(x-1); cout << seg.query(*prev(it), *it) << endl; } } return 0; }