結果

問題 No.2292 Interval Union Find
ユーザー miiemiie
提出日時 2024-11-08 23:05:41
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 7,290 bytes
コンパイル時間 8,580 ms
コンパイル使用メモリ 350,856 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-11-08 23:06:02
合計ジャッジ時間 17,907 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 102 ms
5,248 KB
testcase_05 AC 93 ms
5,248 KB
testcase_06 AC 64 ms
5,248 KB
testcase_07 AC 90 ms
5,248 KB
testcase_08 AC 94 ms
5,248 KB
testcase_09 AC 95 ms
5,248 KB
testcase_10 AC 109 ms
5,248 KB
testcase_11 AC 82 ms
5,248 KB
testcase_12 AC 97 ms
5,248 KB
testcase_13 AC 76 ms
5,248 KB
testcase_14 AC 77 ms
5,248 KB
testcase_15 AC 81 ms
5,248 KB
testcase_16 AC 78 ms
5,248 KB
testcase_17 AC 91 ms
5,248 KB
testcase_18 AC 131 ms
13,056 KB
testcase_19 AC 224 ms
12,928 KB
testcase_20 AC 210 ms
13,056 KB
testcase_21 AC 180 ms
8,960 KB
testcase_22 AC 177 ms
8,960 KB
testcase_23 AC 181 ms
8,960 KB
testcase_24 AC 168 ms
8,960 KB
testcase_25 AC 173 ms
8,960 KB
testcase_26 AC 172 ms
8,960 KB
testcase_27 AC 172 ms
8,960 KB
testcase_28 AC 167 ms
9,088 KB
testcase_29 AC 173 ms
9,088 KB
testcase_30 AC 172 ms
9,088 KB
testcase_31 AC 170 ms
9,088 KB
testcase_32 AC 169 ms
8,960 KB
testcase_33 AC 175 ms
8,832 KB
testcase_34 AC 164 ms
9,088 KB
testcase_35 AC 168 ms
8,960 KB
testcase_36 AC 164 ms
9,088 KB
testcase_37 AC 167 ms
8,960 KB
testcase_38 AC 176 ms
8,832 KB
testcase_39 AC 175 ms
8,960 KB
testcase_40 AC 173 ms
8,832 KB
testcase_41 AC 51 ms
5,248 KB
testcase_42 AC 52 ms
5,248 KB
testcase_43 AC 54 ms
5,248 KB
testcase_44 AC 60 ms
5,248 KB
testcase_45 AC 60 ms
5,248 KB
testcase_46 AC 63 ms
5,248 KB
testcase_47 AC 70 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all> 
using namespace atcoder;

// 数値型
using mint = modint998244353;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
using Pli = pair<ll, int>;
using Pil = pair<int, ll>;

// vector関連
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
template<typename T>
using vc = vector<T>;
template<typename T>
using vvc = vector<vc<T>>;
template<typename T>
using vvvc = vector<vvc<T>>;
template<typename T>
using vvvvc = vector<vvvc<T>>;

// priority_queue
template<typename T>
using pq = priority_queue<T>;
template<typename T>
using pqg = priority_queue<T, vc<T>, greater<T>>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = a; i < (int)(b); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MIN(vec) *min_element(vec)
#define MAX(vec) *max_element(vec)
#define next_perm(vec) (vec).begin(), (vec).end()
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define el "\n"
#define Yes cout << "Yes" << el
#define No cout << "No" << el
#define YES cout << "YES" << el
#define NO cout << "NO" << el
#define minus1 cout << -1 << el
#define EPS 1e-8
#define Equal(a, b) (fabs((a)-(b)) < EPS) 
#define dbg(x) cerr << #x << "=" << x << el 

// 定数
const string abc = "abcdefghijklmnopqrstuvwxyz";
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};
constexpr int DX8[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int DY8[] = {0, 1, 0, -1, 1, -1, 1, -1};

template<typename T1, typename T2>
ostream &operator<< (ostream &os, pair<T1, T2> p) {
    os << "{" << p.first << "," << p.second << "}";
    return os;
}
template<typename T>
ostream &operator<< (ostream &os, vc<T> &vec) {
    int sz = vec.size();
    rep(i, sz){
        os << vec[i] << (i==sz-1?"":" ");
    }
    return os;
}

istream &operator>> (istream &is, mint &a) {
    ll x;
    is >> x;
    a = x;
    return is;
}
template<typename T1, typename T2>
istream &operator>> (istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}
template<typename T>
istream &operator>> (istream &is, vc<T> &vec) {
    int sz = vec.size();
    rep(i, sz) { is >> vec[i]; }
    return is;
}

template<typename T>
ostream &operator<< (ostream &os, set<T> &st) {
  for(const T &elem : st) {
    os << elem;
  }
  return os;
}
/// @brief aとbの最大値をaに格納。更新があったかbool値を返す
/// @tparam T1 
/// @tparam T2 
/// @param a 
/// @param b 
/// @return bool
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b){
    bool ret = a<b;
    if(ret) a = b;
    return ret;
}

/// @brief aとbの最小値をaに格納。更新があったかbool値を返す
/// @tparam T1 
/// @tparam T2 
/// @param a 
/// @param b 
/// @return bool
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b){
    bool ret = a>b;
    if(ret) {a = b;}
    return ret;
}

inline void YesNo(bool flag){
    if(flag) {Yes;}
    else {No;}
    return;
}

inline void YESNO(bool flag){
    if(flag) {YES;}
    else {NO;}
    return;
}

inline bool outof(ll x, ll xlim){
    return (x<0 || x>=xlim);
}

template<typename T>
inline T sqnorm(T x, T y){
    return x*x+y*y;
}

/// @brief char->int
/// @param c 
/// @return int
inline int ctoi(char c){
    return c-'0';
}

/// @brief xを素因数分解
/// @param x 
/// @return vector<Pli>, 素因数の昇順に {p, cnt}
vector<Pli> prime_fact(ll x){
    vector<Pli> ret;
    for(ll i=2; i*i<=x; i++){
        if(x%i == 0){
            ret.emplace_back(i, 0);
            while(x%i == 0){
                ret.back().second++;
                x /= i;
            }
        }
    }
    if(x != 1) ret.emplace_back(x, 1);
    return ret;
}

/// @brief xの約数列挙
/// @param x 
/// @return vll, 約数の昇順
vll divisor_enum(ll x){
    vector<ll> ret;
    for(ll i=1; i*i<=x; i++){
        if(x%i == 0){
            ret.push_back(x/i);
            ret.push_back(i);
        }
    }
    sort(all(ret));
    UNIQUE(ret);
    return ret;
}

/// @brief 繰り返し二乗法。
/// @tparam T 
/// @param x 
/// @param k 
/// @param op 
/// @param e 
/// @return 
template<typename T>
T pow_t(T x, ll k, T (*op)(T, T), T (*e)()){
    T ret = e();
    while(k){
        if(k&1) ret *= x;
        x *= x;
        k >>= 1;
    }
    return ret;
}

ll powll(ll x, ll k){
    return pow_t<ll>(x, k, [](ll a, ll b) -> ll{return a*b;}, []() -> ll{return 1;});
}

inline int pop_cnt(ll x) { return __builtin_popcountll(x); }
inline int top_bit(ll x) { return (x==0?-1:63-__builtin_clzll(x));}

void main2();

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    main2();
}





template<typename T>
struct RangeSet {
    private:
    bool m_open;
    set<pair<T, T>> st;
    public:
    RangeSet(bool open):m_open(open){}
    void add(T l, T r) {
        assert(l <= r-m_open);
        auto it = st.lower_bound({l+1, l+1});
        if(it != st.begin() && prev(it)->second-m_open >= l){
            l = prev(it)->first;
            if(r < prev(it)->second) r = prev(it)->second;
            it = st.erase(prev(it));
        }
        while(it != st.end() && it->first+m_open <= r){
            if(r < it->second) r = it->second;
            it = st.erase(it);
        }
        st.insert({l, r});
    }
    void add(T x) { add(x, x+m_open); }
    void del(T l, T r) {
        int nl=l+1, nr = r-1;
        assert(l <= r-m_open);
        auto it = st.lower_bound({l, l});
        if(it != st.begin() && prev(it)->second > l+m_open) it--;
        while(it != st.end() && it->first < r+m_open){
            if(nr < it->second) nr = it->second;
            if(nl > it->first) nl = it->first;
            it = st.erase(it);
        }
        if(r <= nr) st.insert({r-m_open, nr});
        if(nl+m_open <= l) st.insert({nl, l});
    }
    void del(T x) { del(x, x+m_open); }
    bool covered(T l, T r) {
        assert(l<=r);
        auto it = st.lower_bound({l+1, l+1});
        return it != st.begin() && prev(it)->second >= r; 
    }
    bool covered(T x) { return covered(x, x+m_open); }
    int size(T x) {
        auto it = st.lower_bound({x+1, x+1});
        if(it == st.begin() || prev(it)->second+m_open < x) return 0;
        return prev(it)->second-prev(it)->first+1-m_open;
    }
    int size() { return st.size(); }
    T mex(T base=0) {}
};

void main2(){
  int n, q;
  cin >> n >> q;
  RangeSet<int> rst(false);
  rep(i, q){
    int t;
    cin >> t;
    if(t == 1){
      int l, r;
      cin >> l >> r;
      rst.add(l, r);
    }
    if(t == 2){
      int l, r;
      cin >> l >> r;
      rst.del(l, r);
    }
    if(t == 3){
      int u, v;
      cin >> u >> v;
      if(u > v) swap(u, v);
      cout << (rst.covered(u, v) || u==v ?1:0) << el;
    }
    if(t == 4){
      int x;
      cin >> x;
      cout << max(1, rst.size(x)) << el;
    }
  }
}
0