結果

問題 No.2292 Interval Union Find
ユーザー hikikomorihikikomori
提出日時 2023-03-30 02:03:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 551 ms / 5,000 ms
コード長 3,311 bytes
コンパイル時間 7,691 ms
コンパイル使用メモリ 322,644 KB
実行使用メモリ 35,976 KB
最終ジャッジ日時 2023-10-22 01:08:42
合計ジャッジ時間 27,728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,084 KB
testcase_01 AC 3 ms
8,084 KB
testcase_02 AC 3 ms
8,084 KB
testcase_03 AC 3 ms
8,084 KB
testcase_04 AC 441 ms
23,672 KB
testcase_05 AC 438 ms
23,936 KB
testcase_06 AC 439 ms
23,672 KB
testcase_07 AC 423 ms
23,324 KB
testcase_08 AC 526 ms
35,016 KB
testcase_09 AC 518 ms
35,016 KB
testcase_10 AC 539 ms
35,016 KB
testcase_11 AC 518 ms
34,752 KB
testcase_12 AC 514 ms
35,016 KB
testcase_13 AC 503 ms
34,488 KB
testcase_14 AC 529 ms
34,752 KB
testcase_15 AC 531 ms
34,752 KB
testcase_16 AC 533 ms
34,752 KB
testcase_17 AC 551 ms
35,012 KB
testcase_18 AC 291 ms
35,976 KB
testcase_19 AC 374 ms
35,976 KB
testcase_20 AC 389 ms
35,976 KB
testcase_21 AC 438 ms
35,520 KB
testcase_22 AC 442 ms
35,516 KB
testcase_23 AC 437 ms
35,516 KB
testcase_24 AC 436 ms
35,516 KB
testcase_25 AC 432 ms
35,516 KB
testcase_26 AC 430 ms
35,516 KB
testcase_27 AC 432 ms
35,516 KB
testcase_28 AC 431 ms
35,516 KB
testcase_29 AC 432 ms
35,516 KB
testcase_30 AC 440 ms
35,516 KB
testcase_31 AC 431 ms
35,516 KB
testcase_32 AC 441 ms
35,516 KB
testcase_33 AC 436 ms
35,516 KB
testcase_34 AC 437 ms
35,516 KB
testcase_35 AC 443 ms
35,516 KB
testcase_36 AC 456 ms
35,516 KB
testcase_37 AC 443 ms
35,516 KB
testcase_38 AC 430 ms
35,516 KB
testcase_39 AC 434 ms
35,516 KB
testcase_40 AC 434 ms
35,516 KB
testcase_41 AC 244 ms
19,976 KB
testcase_42 AC 251 ms
19,976 KB
testcase_43 AC 256 ms
19,976 KB
testcase_44 AC 328 ms
19,976 KB
testcase_45 AC 343 ms
19,976 KB
testcase_46 AC 342 ms
19,976 KB
testcase_47 AC 374 ms
20,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<ll>>;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<long long, long long>;
using vpll = vector<pll>;
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 <class T>
inline T CHMAX(T& a, const T b) {
    return a = (a < b) ? b : a;
}
template <class T>
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<S> v(n, 0);
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(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);
        } 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);
        } 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 << 1 << endl;
            }
        } else {
            ll hei = lower_bound(ALL(za), query[i][1]) - za.begin();
            ll r = seg.max_right<g>(hei);
            ll l = seg.min_left<g>(hei);
            cout << za[r] - za[l] + 1 << endl;
        }
    }
}
0