#include using namespace std; #include using namespace atcoder; using ll = long long; using ld = long double; using P = pair; using Graph = vector>; using vi = vector; using vl = vector; using vll = vector; using vvi = vector; using vvl = vector; using vvll = vector; using vs = vector; using vc = vector; using vvc = vector; using pll = pair; using vpll = vector; using mint = modint1000000007; const long double EPS = 1e-18; const long double PI = acos(-1.0L); #define reps(i, a, n) for (ll i = (a); i < (ll)(n); i++) #define rep(i, n) for (ll i = (0); i < (ll)(n); i++) #define rrep(i, n) for (ll i = (1); i < (ll)(n + 1); i++) #define repd(i, n) for (ll i = n - 1; i >= 0; i--) #define rrepd(i, n) for (ll i = n; i >= 1; i--) #define ALL(n) begin(n), end(n) #define IN(a, x, b) (a <= x && x < b) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); template inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; } template inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; } using S = long long; using F = long long; const S INF = 8e18; const F ID = 8e18; S op(S a, S b) { return std::min(a, b); } S e() { return INF; } S mapping(F f, S x) { return (f == ID ? x : f); } F composition(F f, F g) { return (f == ID ? g : f); } F id() { return ID; } ll target = 0; bool g(S x) { return x > target; } int main() { ll N; cin >> N; ll Q; cin >> Q; vll za; za.push_back(0); za.push_back(1e9 + 100); vvll query(2e5 + 50); rrep(i, Q) { ll type; cin >> type; query[i].push_back(type); if (type != 4) { ll u, v; cin >> u >> v; query[i].push_back(u); query[i].push_back(v); za.push_back(u); za.push_back(v); } else { ll u; cin >> u; query[i].push_back(u); za.push_back(u); } } sort(ALL(za)); za.erase(unique(ALL(za)), za.end()); ll n = za.size(); vector v(n, 0); lazy_segtree seg(v); lazy_segtree seg2(v); rrep(i, Q) { if (query[i][0] == 1) { ll l = lower_bound(ALL(za), query[i][1]) - za.begin(); ll r = lower_bound(ALL(za), query[i][2]) - za.begin(); seg.apply(l, r, 1); seg2.apply(l, r + 1, 1); } else if (query[i][0] == 2) { ll l = lower_bound(ALL(za), query[i][1]) - za.begin(); ll r = lower_bound(ALL(za), query[i][2]) - za.begin(); seg.apply(l, r, 0); seg2.apply(l + 1, r, 0); } else if (query[i][0] == 3) { ll l = lower_bound(ALL(za), query[i][1]) - za.begin(); ll r = lower_bound(ALL(za), query[i][2]) - za.begin(); if (r < l) { swap(l, r); } if (l != r) { cout << seg.prod(l, r) << endl; } else { cout << seg2.prod(l, r + 1) << endl; } } else { ll hei = lower_bound(ALL(za), query[i][1]) - za.begin(); ll r = seg.max_right(hei); ll l = seg.min_left(hei); cout << za[r] - za[l] + 1 << endl; } } }