結果

問題 No.674 n連勤
ユーザー rokahikou1rokahikou1
提出日時 2021-02-26 12:58:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,718 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 172,152 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 03:54:44
合計ジャッジ時間 3,283 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 75 ms
6,940 KB
testcase_14 AC 79 ms
6,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

template <typename T> class IntervalSet : std::set<std::pair<T, T>> {
  private:
    const T INF = std::numeric_limits<T>::max() - 65;
    bool isMergeAdjacent;

  public:
    /**
     * @brief Construct a new Interval Set object
     *
     * @param f if merge adjacent interval
     */
    IntervalSet(bool f) : isMergeAdjacent(f) {
        this->emplace(-INF - 1, -INF);
        this->emplace(INF, INF + 1);
    }

    auto get(T p) const {
        auto it = this->upper_bound({p, INF});
        if(it == this->begin() || (--it)->second < p)
            return this->end();
        return it;
    }

    void insert(T l, T r) {
        auto it = std::prev(this->lower_bound({l, r}));
        if(it->first <= l && l + !isMergeAdjacent <= it->second) {
            l = std::min(l, it->first);
            r = std::max(r, it->first);
            this->erase(it);
        }
        it = this->lower_bound({l, r});
        while(1) {
            if(l <= it->first && it->first <= r) {
                r = std::max(r, it->second);
                it = this->erase(it);
            } else
                break;
        }
        this->emplace(l, r);
    }

    void remove(T l, T r) {}

    bool same(T p, T q) const {
        auto it = get(p);
        return it != this->end() && it->first <= q && q <= it->second;
    }
};

int main() {
    long long d, q;
    std::cin >> d >> q;
    IntervalSet<long long> st(true);
    long long res = 0;
    for(int i = 0; i < q; i++) {
        long long x, y;
        std::cin >> x >> y;
        y++;
        st.insert(x, y);
        auto it = st.get(x);
        res = std::max(it->second - it->first, res);
        std::cout << res << std::endl;
    }
}
0