#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("Yes");}else{puts("No");} // long long version const int MAX_N = 300005; ll bit[MAX_N+1][2]; int nn = MAX_N; // 1-index void adds(int a, ll w, int z){ for(int x = a; x <= nn; x += x & -x) bit[x][z] += w; } ll sums(int a, int z){ // bit[1,a]の和を返す. ll ret = 0; for(int x = a; x > 0; x -= x & -x) ret += bit[x][z]; return ret; } int main() { int n, q; cin >> n >> q; ll a[n+1] = {}; srep(i,1,n+1)cin >> a[i]; srep(i,1,n+1){ adds(i, 1, 0); adds(i, a[i], 1); } rep(loop, q){ int query, x; cin >> query >> x; if(query == 1){ if(sums(x, 0) != sums(x+1, 0)){ adds(x+1, -1, 0); } } if(query == 2){ if(sums(x, 0) == sums(x+1, 0)){ adds(x+1, 1, 0); } } if(query == 3){ adds(x, 1, 1); } if(query == 4){ ll tmp = sums(x, 0); int left, right; int l = 1, r = x; while(l < r){ int m = (l + r) / 2; if(sums(m, 0) == tmp){ r = m; }else{ l = m + 1; } } left = l; l = x, r = n; while(l < r){ int m = (l + r) / 2 + 1; if(sums(m, 0) == tmp){ l = m; }else{ r = m - 1; } } right = l; ll ans = sums(right, 1); if(left > 1){ ans -= sums(left - 1, 1); } cout << ans << endl; } } return 0; }