/* ---------- STL Libraries ---------- */ // IO library #include #include #include #include #include // algorithm library #include #include #include #include #include // container library #include #include #include #include #include #include #include #include #include #include #include /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ const int MAX_N = 200000; int bit[MAX_N + 1], n; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add_to(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } signed main() { int q; cin >> n >> q; vector S(n + 1, 0); for (int i = 0; i < n; i++) { cin >> S[i + 1]; S[i + 1] += S[i]; } set st; for (int i = 0; i <= n - 1; i++) st.insert(i); for (int i = 0; i < q; i++) { int query, x; cin >> query >> x; if (query == 1) { st.erase(st.find(x)); } else if (query == 2) { st.insert(x); } else if (query == 3) { add_to(x, 1); } else { auto it = st.lower_bound(x); int upper = (it == st.end()) ? n : *it; it--; int lower = *it + 1; cout << S[upper] - S[lower - 1] + sum(upper) - sum(lower - 1) << endl; } } return 0; }