結果

問題 No.2292 Interval Union Find
ユーザー t98slidert98slider
提出日時 2023-03-30 02:55:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,625 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 96,416 KB
最終ジャッジ日時 2024-04-27 05:13:24
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:13:10: error: incomplete type 'std::ios' {aka 'std::basic_ios<char>'} used in nested name specifier
   13 |     ios::sync_with_stdio(false);
      |          ^~~~~~~~~~~~~~~
main.cpp:14:5: error: 'cin' was not declared in this scope
   14 |     cin.tie(0);
      |     ^~~
main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include <atcoder/all>
  +++ |+#include <iostream>
    2 | using namespace std;
main.cpp:38:13: error: 'cout' was not declared in this scope
   38 |             cout << seg.prod(u, v) << '\n';
      |             ^~~~
main.cpp:38:13: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
main.cpp:43:13: error: 'cout' was not declared in this scope
   43 |             cout << ca[R] - ca[L] + 1 << '\n';
      |             ^~~~
main.cpp:43:13: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?

ソースコード

diff #

#include <atcoder/all>
using namespace std;

using S = int;
S e(){return 1;}
S op(S lhs, S rhs){return min(lhs, rhs);}
using F = int;
S mapping(F f, S x){return f == -1 ? x : f;}
F composition(F f, F g){return f == -1 ? g : f;}
F id(){return -1;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q, type, u, v, L, R;
    cin >> N >> Q;
    vector<int> ca = {1, N};
    vector<tuple<int, int, int>> query(Q);
    for(int i = 0; i < Q; i++){
        cin >> get<0>(query[i]) >> get<1>(query[i]);
        if(get<0>(query[i]) != 4) cin >> get<2>(query[i]);
        ca.emplace_back(get<1>(query[i]));
        ca.emplace_back(get<2>(query[i]));
    }
    sort(ca.begin(), ca.end());
    ca.erase(unique(ca.begin(), ca.end()), ca.end());
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(vector<int>(ca.size(), 0));
    for(int i = 0; i < Q; i++){
        tie(type, u, v) = query[i];
        if(type <= 2){
            L = lower_bound(ca.begin(), ca.end(), u) - ca.begin();
            R = lower_bound(ca.begin(), ca.end(), v) - ca.begin();
            seg.apply(L, R, 2 - type);
        }else if(type == 3){
            u = lower_bound(ca.begin(), ca.end(), u) - ca.begin();
            v = lower_bound(ca.begin(), ca.end(), v) - ca.begin();
            if(u > v) swap(u, v);
            cout << seg.prod(u, v) << '\n';
        }else{
            u = lower_bound(ca.begin(), ca.end(), u) - ca.begin();
            L = seg.min_left(u, [](int v){return v != 0; });
            R = seg.max_right(u, [](int v){return v != 0; });
            cout << ca[R] - ca[L] + 1 << '\n';
        }
    }
}
0