#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; class BIT { private: ll N; vector node; public: BIT(ll M) { node = vector(M + 1, 0); N = M; } ll sum(ll i) { ll s = 0; while (i > 0) { s += node[i]; i -= i & -i; } return s; } ll sum(ll i, ll j) { ll l = sum(i - 1); ll r = sum(j); return r - l; } void add(ll i, ll x) { while (i <= N) { node[i] += x; i += i & -i; } } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N, Q; scanf("%lld %lld", &N, &Q); BIT bit(N + 5); multiset ms; for (ll i = 1; i <= N + 1; i++) ms.insert(i); for (ll i = 0; i < N; i++) { ll x; scanf("%lld", &x); bit.add(i + 1, x); } while (Q--) { ll q, x; scanf("%lld %lld", &q, &x); if (q == 1) { auto itr = ms.upper_bound(x); ms.erase(itr); } if (q == 2) { ms.insert(x + 1); } if (q == 3) { bit.add(x, 1); } if (q == 4) { auto itr1 = ms.upper_bound(x); auto itr2 = itr1; itr2--; printf("%lld\n", bit.sum(*itr2, *itr1 - 1)); } } return 0; }