結果

問題 No.2292 Interval Union Find
ユーザー milanis48663220milanis48663220
提出日時 2023-05-05 22:31:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,477 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 122,500 KB
実行使用メモリ 5,160 KB
最終ジャッジ日時 2023-08-15 05:09:31
合計ジャッジ時間 11,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 RE -
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 268 ms
4,828 KB
testcase_05 AC 258 ms
5,160 KB
testcase_06 AC 270 ms
4,892 KB
testcase_07 AC 257 ms
4,828 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 AC 167 ms
4,380 KB
testcase_42 AC 171 ms
4,384 KB
testcase_43 AC 181 ms
4,384 KB
testcase_44 AC 221 ms
4,380 KB
testcase_45 AC 224 ms
4,384 KB
testcase_46 AC 228 ms
4,384 KB
testcase_47 AC 244 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/lazysegtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const int inf = 1e9;

int op(int x, int y){
    return min(x, y);
}

int e(){
    return inf;
}

int id(){
    return -1;
}

int mapping(int f, int x){
    if(f == id()) return x;
    return f;
}

int composition(int f, int g){
    if(f == id()) return g;
    return f;
}

using Seg = atcoder::lazy_segtree<int, op, e, int, mapping, composition, id>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, q; cin >> n >> q;
    Seg seg(vector<int>(n-1, 0));
    while(q--){
        int t; cin >> t;
        if(t == 1){
            int l, r; cin >> l >> r; l--; r--;
            seg.apply(l, r, 1);
        }else if(t == 2){
            int l, r; cin >> l >> r; l--; r--;
            seg.apply(l, r, 0);
        }else if(t == 3){
            int u, v; cin >> u >> v; u--; v--;
            if(u > v) swap(u, v);
            if(seg.prod(u, v) == 0){
                cout << 0 << endl;
            }else{
                cout << 1 << endl;
            }
        }else{
            int v; cin >> v; v--;
            auto g = [&](int x){
                return x >= 1;
            };
            int r = seg.max_right(v, g);
            int l = seg.min_left(v, g);
            cout << r-l+1 << endl;
        }
    }
}
0