/* -*- coding: utf-8 -*- * * 833.cc: No.833 かっこいい電車 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; template struct BIT { int n; T bits[MAX_N + 1]; BIT() {} void init(int _n) { n = _n; //memset(bits, 0, sizeof(bits)); } T sum(int x) { T s = 0; while (x > 0) { s += bits[x]; x -= (x & -x); } return s; } void add(int x, T v) { while (x <= n) { bits[x] += v; x += (x & -x); } } int lower_bound(T v) { int k = 1; while ((k << 1) <= n) k <<= 1; int x = 0; for (; k > 0; k >>= 1) if (x + k <= n && bits[x + k] < v) { x += k; v -= bits[x]; } return x + 1; } }; /* global variables */ BIT bit0; BIT bit1; /* subroutines */ /* main */ int main() { int n, q; scanf("%d%d", &n, &q); bit0.init(n + 1); bit1.init(n + 1); for (int i = 1; i <= n; i++) { int ai; scanf("%d", &ai); bit0.add(i, 1); bit1.add(i, (ll)ai); } while (q--) { int op, x; scanf("%d%d", &op, &x); if (op == 1) { // connect if (bit0.sum(x) < bit0.sum(x + 1)) bit0.add(x + 1, -1); } else if (op == 2) { // separate if (bit0.sum(x) == bit0.sum(x + 1)) bit0.add(x + 1, 1); } else if (op == 3) { // remodel bit1.add(x, 1); } else { // attractiveness int k = bit0.sum(x); int i0 = bit0.lower_bound(k); int i1 = bit0.lower_bound(k + 1); //printf("x=%d, k=%d, i0,i1=%d,%d\n", x, k, i0, i1); printf("%lld\n", bit1.sum(i1 - 1) - bit1.sum(i0 - 1)); } } return 0; }