#include #include using namespace std; using namespace atcoder; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for(int i = 0; i < (int)(n); ++i) #define rep2(i, n) for(int i = 0; i < (int)(n); ++i) #define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i) #define ALL(a) a.begin(), a.end() #define Sort(a) sort(a.begin(), a.end()) #define RSort(a) sort(a.rbegin(), a.rend()) typedef long long int ll; typedef unsigned long long ul; typedef long double ld; typedef vector vi; typedef vector vll; typedef vector vc; typedef vector vst; typedef vector vd; typedef vector vld; typedef pair P; template long long sum(const T& a){ return accumulate(a.begin(), a.end(), 0LL); } template auto min(const T& a){ return *min_element(a.begin(), a.end()); } template auto max(const T& a){ return *max_element(a.begin(), a.end()); } const long long MINF = 0x7fffffffffff; const long long INF = 0x1fffffffffffffff; const long long MOD = 1000000007; const long double EPS = 1e-9; const long double PI = acos(-1); template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template istream &operator>>(istream &is, pair &p){ is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const pair &p){ os << "(" << p.first << ", " << p.second << ")"; return os; } template istream &operator>>(istream &is, vector &v){ for(T &in : v) is >> in; return is; } template ostream &operator<<(ostream &os, const vector &v){ for(int i = 0; i < (int) v.size(); ++i){ os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, const map &mp){ for(auto &[key, val] : mp){ os << key << ":" << val << " "; } return os; } template ostream &operator<<(ostream &os, const set &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, const multiset &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, queue q){ while(q.size()){ os << q.front() << " "; q.pop(); } return os; } template ostream &operator<<(ostream &os, deque q){ while(q.size()){ os << q.front() << " "; q.pop_front(); } return os; } template ostream &operator<<(ostream &os, stack st){ while(st.size()){ os << st.top() << " "; st.pop(); } return os; } template ostream &operator<<(ostream &os, priority_queue pq){ while(pq.size()){ os << pq.top() << " "; pq.pop(); } return os; } template inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; } template inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; } template void in(T&... a){ (cin >> ... >> a); } void out(){ cout << '\n'; } template void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template void inGraph(vector>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; ++i){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } } template struct DynamicUnionFind{ unordered_map par, siz; DynamicUnionFind(){ } void init(const T &x){ par[x] = x; siz[x] = 1; } T root(const T &x){ if(par.find(x) == par.end()){ init(x); } if(par[x] == x) return x; return par[x] = root(par[x]); } void unite(const T &x, const T &y){ if(par.find(x) == par.end()){ init(x); } if(par.find(y) == par.end()){ init(y); } int rx = root(x); int ry = root(y); if(size(rx) < size(ry)) swap(rx, ry); par[rx] = ry; siz[ry] += siz[rx]; } bool same(const T &x, const T &y){ int rx = root(x); int ry = root(y); return rx == ry; } T size(const T &x){ if(par.find(x) == par.end()){ init(x); } return siz[root(x)]; } }; template struct BinaryIndexedTree{ int N; vector BIT; BinaryIndexedTree(const int &N): N(N), BIT(N + 1, 0){ } T get(int i){ return sum(i + 1) - sum(i); } void add(int i, T x){ i++; while(i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i) const { T ans = 0; while(i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } T sum(int L, int R) const { return sum(R) - sum(L); } int lower_bound(T x) const { if(x <= 0){ return 0; }else{ int v = 0, r = 1; while(r < N) r = r << 1; for(int len = r; len > 0; len = len >> 1){ if(v + len < N && BIT[v + len] < x){ x -= BIT[v + len]; v += len; } } return v; } } int upper_bound(T x) const { if(x < 0){ return 0; }else{ int v = 0, r = 1; while(r <= N) r = r << 1; for(int len = r; len > 0; len = len >> 1){ if(v + len <= N && BIT[v + len] <= x){ x -= BIT[v + len]; v += len; } } return v; } } }; template struct compress{ vector sorted, compressed; compress(const vector& vec){ int n = vec.size(); compressed.resize(n); for(T x : vec){ sorted.emplace_back(x); } sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end()); for(int i = 0; i < n; ++i){ compressed[i] = lower_bound(sorted.begin(), sorted.end(), vec[i]) - sorted.begin(); } } int get(const T& x) const{ return lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin(); } T inv(const T& x) const{ return sorted[x]; } size_t size() const{ return sorted.size(); } vector getCompressed() const{ return compressed; } }; // https://mugen1337.github.io/procon/DataStructure/RangeSet.hpp template struct RangeSet{ set> st; T TINF; RangeSet(){ TINF=numeric_limits::max()/2; st.emplace(TINF,TINF); st.emplace(-TINF,-TINF); } // [l,r] covered? bool covered(T l,T r){ assert(l<=r); auto ite=prev(st.lower_bound({l+1,l+1})); return ite->first<=l and r<=ite->second; } bool covered(T x){ return covered(x,x); } // [l, r]がカバーされているなら,その区間を返す. されていないなら[-TINF,-TINF]を返す pair covered_by(T l,T r){ assert(l<=r); auto ite=prev(st.lower_bound({l+1,l+1})); if(ite->first<=l and r<=ite->second) return *ite; return make_pair(-TINF,-TINF); } pair covered_by(T x){ return covered_by(x,x); } // insert[l,r], 増加量を返す T insert(T l,T r){ assert(l<=r); auto ite=prev(st.lower_bound({l+1,l+1})); if(ite->first<=l and r<=ite->second) return T(0); T sum_erased=T(0); if(ite->first<=l and l<=ite->second+1){ l=ite->first; sum_erased+=ite->second-ite->first+1; ite=st.erase(ite); }else ite=next(ite); while(r>ite->second){ sum_erased+=ite->second-ite->first+1; ite=st.erase(ite); } if(ite->first-1<=r and r<=ite->second){ sum_erased+=ite->second-ite->first+1; r=ite->second; st.erase(ite); } st.emplace(l,r); return r-l+1-sum_erased; } T insert(T x){ return insert(x,x); } // erase [l,r], 減少量を返す T erase(T l,T r){ assert(l<=r); auto ite=prev(st.lower_bound({l+1,l+1})); if(ite->first<=l and r<=ite->second){ // 完全に1つの区間に包含されている if(ite->firstfirst,l-1); if(rsecond) st.emplace(r+1,ite->second); st.erase(ite); return r-l+1; } T ret=T(0); if(ite->first<=l and l<=ite->second){ ret+=ite->second-l+1;// 消えた if(ite->firstfirst,l-1); ite=st.erase(ite);// 次へ }else ite=next(ite); while(ite->second<=r){ ret+=ite->second-ite->first+1; ite=st.erase(ite); } // 右端が区間の間にあるか if(ite->first<=r and r<=ite->second){ ret+=r-ite->first+1; if(rsecond) st.emplace(r+1,ite->second); st.erase(ite); } return ret; } T erase(T x){ return erase(x,x); } // number of range int size(){ return (int)st.size()-2; } // mex [x,~) T mex(T x=0){ auto ite=prev(st.lower_bound({x+1,x+1})); if(ite->first<=x and x<=ite->second) return ite->second+1; else return x; } void output(){ cout<<"RangeSet : "; for(auto &p:st){ if(p.first==-TINF or p.second==TINF) continue; cout<<"["<> query(q); vll c; rep(i, q){ ll t; in(t); if(t == 4){ ll v; in(v); query[i] = {t, v, 0}; c.push_back(v); }else{ ll u, v; in(u, v); query[i] = {t, u, v}; c.push_back(u); c.push_back(v); } } compress comp(c); ll m = comp.size(); vll s(m + 1); rep(i, m){ s[i + 1] = s[i] + comp.inv(i); } RangeSet rg; rep(i, q){ auto [t, a, b] = query[i]; a *= 2, b *= 2; ll x = comp.get(a), y = comp.get(b); if(t == 1){ rg.insert(a, b); }else if(t == 2){ rg.erase(a + 1, b - 1); }else if(t == 3){ if(a == b){ out(1); continue; } P r = rg.covered_by(a); if(r.first <= b && b <= r.second){ out(1); }else{ out(0); } }else{ P r = rg.covered_by(a); // out(r); out(max(1LL, (r.second - r.first) / 2 + 1)); } } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); input(); solve(); }