結果

問題 No.2292 Interval Union Find
ユーザー KudeKude
提出日時 2023-05-05 22:34:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 2,677 bytes
コンパイル時間 3,562 ms
コンパイル使用メモリ 241,180 KB
実行使用メモリ 10,608 KB
最終ジャッジ日時 2023-08-15 05:18:16
合計ジャッジ時間 15,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 201 ms
7,716 KB
testcase_05 AC 201 ms
7,692 KB
testcase_06 AC 207 ms
7,648 KB
testcase_07 AC 191 ms
7,428 KB
testcase_08 AC 237 ms
10,044 KB
testcase_09 AC 236 ms
10,012 KB
testcase_10 AC 241 ms
10,012 KB
testcase_11 AC 243 ms
10,104 KB
testcase_12 AC 236 ms
10,072 KB
testcase_13 AC 232 ms
10,044 KB
testcase_14 AC 238 ms
10,048 KB
testcase_15 AC 247 ms
10,072 KB
testcase_16 AC 242 ms
10,104 KB
testcase_17 AC 249 ms
10,104 KB
testcase_18 AC 143 ms
10,416 KB
testcase_19 AC 212 ms
10,520 KB
testcase_20 AC 212 ms
10,368 KB
testcase_21 AC 204 ms
10,360 KB
testcase_22 AC 207 ms
10,412 KB
testcase_23 AC 202 ms
10,436 KB
testcase_24 AC 201 ms
10,332 KB
testcase_25 AC 202 ms
10,424 KB
testcase_26 AC 222 ms
10,372 KB
testcase_27 AC 204 ms
10,404 KB
testcase_28 AC 206 ms
10,336 KB
testcase_29 AC 204 ms
10,608 KB
testcase_30 AC 203 ms
10,300 KB
testcase_31 AC 203 ms
10,336 KB
testcase_32 AC 204 ms
10,428 KB
testcase_33 AC 204 ms
10,364 KB
testcase_34 AC 201 ms
10,388 KB
testcase_35 AC 203 ms
10,384 KB
testcase_36 AC 203 ms
10,276 KB
testcase_37 AC 203 ms
10,320 KB
testcase_38 AC 203 ms
10,376 KB
testcase_39 AC 204 ms
10,424 KB
testcase_40 AC 204 ms
10,408 KB
testcase_41 AC 56 ms
7,516 KB
testcase_42 AC 62 ms
7,528 KB
testcase_43 AC 76 ms
7,536 KB
testcase_44 AC 131 ms
7,516 KB
testcase_45 AC 139 ms
7,520 KB
testcase_46 AC 141 ms
7,476 KB
testcase_47 AC 168 ms
7,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

char op(char x, char y) { return x & y; }
char e() { return true; }
int composition(int f, int g) {
  if (f != -1) return f;
  else return g;
}
int id() { return -1; }
char mapping(int f, char x) { return f != -1 ? f : x; }

template <class S>
struct value_compression : vector<S> {
  bool built = false;
  using VS = vector<S>;
  using VS::VS;
  value_compression(vector<S> v) : vector<S>(move(v)) {}
  void build() {
    sort(this->begin(), this->end());
    this->erase(unique(this->begin(), this->end()), this->end());
    built = true;
  }
  template <class T>
  void convert(T first, T last) {
    assert(built);
    for (; first != last; ++first) *first = (*this)(*first);
  }
  int operator()(S x) {
    assert(built);
    return lower_bound(this->begin(), this->end(), x) - this->begin();
  }
  void clear() {
    this->clear();
    built = false;
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<tuple<int, int, int>> qs(q);
  value_compression<int> vc{0, 1001001001};
  for(auto& [t, i0, i1] : qs) {
    cin >> t;
    if (t == 1 || t == 2) {
      cin >> i0 >> i1;
      vc.emplace_back(i0);
      vc.emplace_back(i1);
    } else if (t == 3) {
      cin >> i0 >> i1;
      if (i0 > i1) swap(i0, i1);
      vc.emplace_back(i0);
      vc.emplace_back(i1);
    } else {
      cin >> i0;
      vc.emplace_back(i0);
    }
  }
  vc.build();
  int sz = vc.size();
  lazy_segtree<char, op, e, int, mapping, composition, id> seg(vector<char>(sz, 0));
  for(auto [t, i0, i1] : qs) {
    if (t == 1) {
      seg.apply(vc(i0), vc(i1), true);
    } else if (t == 2) {
      seg.apply(vc(i0), vc(i1), false);
    } else if (t == 3) {
      cout << int(seg.prod(vc(i0), vc(i1))) << '\n';
    } else {
      int i = vc(i0);
      int l = seg.min_left(i, [](char x) { return x; });
      int r = seg.max_right(i, [](char x) { return x; });
      cout << vc[r] - vc[l] + 1 << '\n';
    }
  }
}
0