結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
rokahikou1
|
| 提出日時 | 2021-02-26 12:58:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,718 bytes |
| コンパイル時間 | 1,661 ms |
| コンパイル使用メモリ | 175,436 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-02 05:20:24 |
| 合計ジャッジ時間 | 3,165 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 8 |
ソースコード
#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;
}
}
rokahikou1