C++#include <bits/stdc++.h>
#define SET(n) fixed<<setprecision(n)
#define _for(a,c,b) for(int a = c;a<=b;a++)
#define debug cout<<"ok\n"
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 4e5+9,inf = 1.01e9,mod = 1e9+7;
const ll INF = 1.01e18+9;
bool tf[N];int cnt = 0;
bool yh = 0;
int mov = 0;//偏移量
int tree[N],a[N];
int n,q;
inline void update(int x,int k){
while(x <= N-10){
tree[x] += k;
x += (x&-x);
}
}
inline int query(ll x){
int ans = 0;
while(x>0){
ans += tree[x];
x -= (x&-x);
}
return ans;
}
void init(){}
void solve(){
cin>>n>>q;
for(int i =1;i<=q;i++){
int op;cin>>op;
if(op == 1){
int x;cin>>x;
if(!(tf[x]^yh))tf[x] = 1^yh,cnt++;
int ini = a[x];a[x] ++;
update(a[x],1);
if(ini>0)update(ini,-1);
if(cnt == n)
mov +=1,yh ^= 1,cnt = 0;
}
else if(op == 2){
int x;cin>>x;
cout<<query(q)-query(x+mov-1)<<'\n';
}
}
}
int main(){
cin.tie(0)->sync_with_stdio(false);
//int t;cin>>t;while(t--)
solve();
return 0;
}
//3 1000
//1 1
//1 2
//1 3
//1 1
//1 2
//1 3
//1 1
//1 2
//1 3
//1 1
//1 2
//1 3
//2 1