#include using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template struct LazySegmentTree { private: int n; vector node; vector lazy; vector updated; T def; function out; function app; function lop; void propagate(int k, E x) { if (updated[k]) { lazy[k] = lop(lazy[k], x); } else { lazy[k] = x; updated[k] = true; } } void evaluate(int k, int l, int r) { if (updated[k]) { node[k] = app(node[k], lazy[k], r - l); if ((r - l) > 1) { propagate(k * 2 + 1, lazy[k]); propagate(k * 2 + 2, lazy[k]); } updated[k] = false; } } public: LazySegmentTree() {} LazySegmentTree(const vector &v, T _def, function _lop, function _app, function _out) { def = _def; out = _out; app = _app; lop = _lop; int vl = (int)v.size(); n = 1; while(n < vl) n *= 2; node.resize(2 * n - 1, def); lazy.resize(2 * n - 1); updated.resize(2 * n - 1, false); for(int i = 0; i < vl; i++) node[i + n - 1] = v[i]; for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]); } void update(int a, int b, E x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; evaluate(k, l, r); if((b <= l) || (r <= a)) return; if((a <= l) && (r <= b)) { propagate(k, x); evaluate(k, l, r); } else { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = out(node[2 * k + 1], node[2 * k + 2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; evaluate(k, l, r); if ((b <= l) || (r <= a)) return def; if ((a <= l) && (r <= b)) return node[k]; T vl = query(a, b, 2 * k + 1, l, (l + r) / 2); T vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return out(vl, vr); } }; template struct SegmentTree { private: int n; vector node; T def; function lop; function out; public: SegmentTree() {} SegmentTree(const vector &v, T _def, function _lop, function _out) { int vl = (int)v.size(); n = 1; while(n < vl) n *= 2; def = _def; lop = _lop; out = _out; node = vector(2 * n - 1, def); for(int i = 0; i < vl; i++) node[i + n - 1] = v[i]; for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]); } void update(int idx, T val) { idx += (n - 1); node[idx] = lop(node[idx], val); while(idx > 0) { idx = (idx - 1) / 2; node[idx] = out(node[idx * 2 + 1], node[idx * 2 + 2]); } } T query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if ((r <= a) || (b <= l)) return def; if ((a <= l) && (r <= b)) return node[k]; return out(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r)); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n, q; cin >> n >> q; vector a(n); rep(i, n) cin >> a[i]; vector> vp(n); rep(i, n) vp[i] = make_pair(i, i); auto lop1 = [](pair a, pair b){ return b; }; auto app1 = [](pair a, pair b, int c){ return b; }; auto out1 = [](pair a, pair b){ return make_pair(a.first + b.first, a.second + b.second); }; LazySegmentTree, pair> range(vp, make_pair(0, 0), lop1, app1, out1); auto lop2 = [](ll a, ll b){ return a + b; }; auto out2 = [](ll a, ll b){ return a + b; }; SegmentTree val(a, 0, lop2, out2); rep(i, q) { ll t, x; cin >> t >> x; x--; if (t == 1) { pair p1 = range.query(x, x + 1); pair p2 = range.query(x + 1, x + 2); range.update(p1.first, p2.second + 1, make_pair(p1.first, p2.second)); } else if (t == 2) { pair p1 = range.query(x, x + 1); pair p2 = range.query(x + 1, x + 2); range.update(p1.first, x + 1, make_pair(p1.first, x)); range.update(x + 1, p2.second + 1, make_pair(x + 1, p2.second)); } else if (t == 3) { val.update(x, 1); } else { pair p = range.query(x, x + 1); cout << val.query(p.first, p.second + 1) << endl; } } return 0; }