//In The Name Of ALLAH!
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define pf push_front
#define Zemur007 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define bpc __builtin_popcountll
#define btz __builtin_ctzll
#define all(x) x.begin() , x.end()
#define allr(x) x.rbegin() , x.rend()
#define F first
#define S second
#define pll pair<ll , ll>
#define turtle tuple<ll , ll , ll>
#define pss pair<string , string>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define indexed_set tree<pll , null_type , less<pll> , rb_tree_tag , tree_order_statistics_node_update>
const ll sz = 1e5 + 5 , INF = 1e18 ,  MOD = 1e9 + 7;
bool used[sz];
ll a[sz] , b[sz] , c[sz] ,  id[sz];
struct BIT{
    vector<ll> ft;
    void assign(ll n){
        ft.assign(n + 1 , 0);
    }
    void update(ll n , ll x , ll val){
        for(ll i = x ; i <= n ; i += i & -i) ft[i] += val;
    }
    ll get(ll x){
        ll ans = 0;
        for(ll i = x ; i >= 0 ; i -= i & -i) ans += ft[i];
        return ans;
    }
    ll query(ll l , ll r){
        return get(r) - get(l - 1);
    }
};
ll mask , i , j , k;
void solve(){
    ll q , t , last = 0 , n = 1; cin >> q >> t;
    map<ll , pll> mp;
    for(k = 1 ; k <= q ; k++){
        ll op; cin >> op;
        if(op == 1){
            cin >> a[k] >> b[k];
            ll l = (a[k] ^ (t * last)) , r = (b[k] ^ (t * last)) , ind;
            for(i = 1 ; i < 1e5; i++){
                if(!used[i]){
                    ind = i;
                    break;
                }
            }
            used[ind] = true;
            mp[ind] = {l , r};
        }
        if(op == 2){
            cin >> id[k];
            mp.erase(id[k]);
            used[id[k]] = false;
        }
        if(op == 3){
            cin >> a[k] >> b[k] >> c[k];
            ll l = (a[k] ^ (t * last)) , r = (b[k] ^ (t * last)) , ans = 0;
            for(auto [x , y] : mp){
                auto [L , R] = y;
                if(max(L , R) < min(l , r)) continue;
                ll cnt = 0;
                for(i = L ; i <= R ; i++){
                    for(j = l ; j <= r ; j++){
                        if(i == j) cnt++;
                    }
                }
                if(cnt >= c[k]) ans++;
            }
            last = ans;
            cout << ans << endl;
        }
    }
}     
 
signed main(){
    Zemur007;
    //open;
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    // for(ll testcase = 1 ; testcase <= t ; testcase++){
    //     cout << "Case " << testcase << ":" << endl;
    //     solve();
    // }
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |