#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define Ma_PI 3.141592653589793 #define eps 0.00000000000000000000000001 #define LONG_INF 10000000000000000LL #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define MOD 998244353 #define REP(i,n) for(long long i = 0;i < n;++i) long long inv(long long now) { long long ans = 1; long long te = MAX_MOD - 2LL; while (te != 0) { if (te % 2 == 1) { ans *= now; ans %= MAX_MOD; } te /= 2; now *= now; now %= MAX_MOD; } return ans; } #define SIZE 100 long long ok_compact[100000 / SIZE * 2] = {}; long long cost[200000]; long long is_connected[200000]; int main(){ #define int long long int n, query; cin >> n >> query; REP(i, n) { cin >> cost[i]; } REP(i, query) { int a; int b; cin >> a >> b; b--; if (a == 1) { if (is_connected[b] == 0) { is_connected[b] = 1; int ok = 1; for (int q = b / SIZE * SIZE; q < (b / SIZE + 1) * SIZE && q < n; ++q) { ok &= is_connected[q]; ok_compact[b / SIZE] += cost[q]; } ok_compact[b / SIZE] *= ok; } } else if (a == 2) { if (is_connected[b] == 1) { is_connected[b] = 0; if (ok_compact[b / SIZE] != 0) { ok_compact[b / SIZE] = 0; } } } else if (a == 3) { cost[b]++; if (ok_compact[b / SIZE] != 0) { ok_compact[b / SIZE]++; } } else { //output; long long now_ans = 0; long long now_itr_back = b;//back <= long long now_itr_front = b; if (ok_compact[b / SIZE] != 0) { now_ans += ok_compact[b / SIZE]; now_itr_back = b/SIZE * SIZE; for (int q = b / SIZE - 1; q >= 0; --q) { if (ok_compact[q] == 0) break; now_ans += ok_compact[q]; now_itr_back = q * SIZE; } now_itr_front = (b / SIZE + 1) * SIZE; for (int q = b / SIZE + 1;; ++q) { if (ok_compact[q] == 0) break; now_ans += ok_compact[q]; now_itr_front = (q+1) * SIZE; } } for (int q = now_itr_back - 1; q >= 0; --q) { if (is_connected[q] == 0) break; now_ans += cost[q]; } for (int q = now_itr_front;; ++q) { now_ans += cost[q]; if (is_connected[q] == 0) break; } cout << now_ans << endl; } } }