#include #include #include #include #include #include int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } using namespace std; typedef long long ll; //定義場所// int i, j, k, l, m, n; int N, Q; vector A; set border;//i両目の左隣に仕切り vector Ans; //////////// int main() { cin >> N >> Q; for (i = 0; i < N; i++) { ll a; cin >> a; A.push_back(a); border.insert(i); } for (i = 0; i < Q; i++) { int q; int x; cin >> q >> x; if (q == 1 && border.count(x - 1) == 1) { border.erase(x - 1); } else if (q == 2 && border.count(x - 1) == 0) { border.insert(x - 1); } else if (q == 3) { A[x - 1]++; } else if (q == 4) { int right = *lower_bound(border.begin(), border.end(), x - 1); int left; if (*lower_bound(border.begin(), border.end(), 0) == right) { left = -1; } else { left = *prev(lower_bound(border.begin(), border.end(), x - 1)); } //cout << left << endl << right << endl; ll ans = 0; for (j = left + 1; j <= right; j++) { ans += A[j]; } Ans.push_back(ans); } } for (i = 0; i < Ans.size(); i++) { cout << Ans[i] << endl; } }