結果
問題 | No.674 n連勤 |
ユーザー |
![]() |
提出日時 | 2020-10-22 15:54:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 1,520 bytes |
コンパイル時間 | 2,111 ms |
コンパイル使用メモリ | 200,236 KB |
最終ジャッジ日時 | 2025-01-15 12:27:18 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; template <class T> class IntervalSet{ /* insert(l, r): 区間[l, r)を挿入 区間が被っているものはマージ O(logN) erase(l, r): 区間[l, r)と被っている区間をすべて削除 O(logN) */ public: set<array<T, 2>> st; IntervalSet(T INF){ st.insert({-INF, -INF}); st.insert({INF, INF}); }; array<T, 2> insert(T l, T r){ // 区間[l, r)を挿入 区間が被っているものはマージ O(logN) // return マージした区間[l, r) auto it = st.lower_bound({l, r}); auto itl = it, itr = it; itl--; while (itl != st.begin() and l <= (*itl)[1]){ r = max(r, (*itl)[1]); l = min(l, (*itl)[0]); itl--; } while (itr != st.end() and (*itr)[0] <= r){ r = max(r, (*itr)[1]); itr++; } st.erase(++itl, itr); st.insert({l, r}); return {l, r}; } void erase(T l, T r){ // erase(l, r): 区間[l, r)と被っている区間をすべて削除 O(logN) auto res = insert(l, r); st.erase(res); } }; int main(){ int64_t d, q; cin >> d >> q; int64_t ma = 0; IntervalSet<int64_t> st(2e18); for (int i = 0; i < q; i++){ int64_t l, r; cin >> l >> r; r++; auto res = st.insert(l, r); ma = max(ma, res[1] - res[0]); cout << ma << endl; } }