#include using i64 = long long; template class Bit { private: int len; T *arr; T init; public: Bit(int length, T initialValue = 0) : len(length), init(initialValue) { arr = new T[length + 1]; for (int i = 0; i <= length; i++) { arr[i] = initialValue; } } ~Bit() { delete[] arr; } void update(int a, T newval) { for (int x = a; x <= len; x += x & -x) arr[x] += newval; } T query(int a) const { T ret = init; for (int x = a; x > 0; x -= x & -x) ret += arr[x]; return ret; } }; int main() { int n, q; std::cin >> n >> q; std::set s; Bit<> bit(n + 10); for (int i = 1; i <= n; i++) { i64 in; std::cin >> in; bit.update(i, in); s.insert(i); } while (q--) { int t, x; std::cin >> t >> x; if (t == 1) { auto it = s.find(x + 1); if (it != s.end()) s.erase(it); } else if (t == 2) { auto it = s.find(x + 1); if (it == s.end()) s.insert(x + 1); } else if (t == 3) { bit.update(x, 1); } else { auto it = s.lower_bound(x), jt = it; int lb = it == s.end() || *it > x ? *--it : *it, ub; if (jt == s.end()) { ub = n + 1; } else if (*jt == x) { jt++; if (jt == s.end()) ub = n + 1; else ub = *jt; } else { ub = *jt; } std::cout << bit.query(ub - 1) - bit.query(lb - 1) << std::endl; } } return 0; }