結果
問題 | No.674 n連勤 |
ユーザー |
|
提出日時 | 2019-05-17 18:37:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 1,347 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 177,084 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 05:59:45 |
合計ジャッジ時間 | 2,419 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<bits/stdc++.h> using namespace std; class RangeSet{ private: const long long INF = 1e18 + 1e8; long long max_range; set<pair<long long, long long>> data; // stores the ranges [L, R) public: RangeSet(): max_range(0), data(){ data.emplace(-INF, -INF); data.emplace(INF, INF); } void insert(long long L, long long R){ // Insert a range [L, R) to the set. // if (L >= R) return; auto it = data.lower_bound(make_pair(L, R)); if (L == it->first) return; // [L, R) is covered by *it. L1 == L < R <= R1 if (L <= (--it)->second){ L = it->first; }else{ ++it; } while (it->first <= R){ if (R < it->second) R = it->second; it = data.erase(it); } data.insert(it, make_pair(L, R)); if (max_range < R - L) max_range = R - L; } long long get_max_range(){ return this->max_range; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); long long D; int Q; cin >> D >> Q; vector<pair<long long, long long>> ABs(Q); for (auto & ab: ABs) cin >> ab.first >> ab.second; RangeSet rset; for (auto & ab: ABs){ rset.insert(ab.first, ab.second + 1LL); cout << rset.get_max_range() << '\n'; } return 0; }