#include #define int long long using namespace std; constexpr int MAXN = 1e5 + 5; int n, q; set st; struct BinaryIndexedTree { int tr[MAXN]; void update(int p, int x) { while (p <= n) { tr[p] += x; p += p & -p; } } int query(int p) { int res = 0; while (p) { res += tr[p]; p -= p & -p; } return res; } } BIT; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> q; for (int i = 1; i <= n; i++) { int x; cin >> x; BIT.update(i, x); st.insert(i); } while (q--) { int op, x; cin >> op >> x; if (op == 1) { st.erase(x + 1); } else if (op == 2) { st.insert(x + 1); } else if (op == 3) { BIT.update(x, 1); } else { auto it = st.upper_bound(x); int l, r; if (it == st.end()) { r = n; it--; l = *it; } else { r = *it - 1; it--; l = *it; } cout << BIT.query(r) - BIT.query(l - 1) << '\n'; } } return 0; }