結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
gyouzasushi
|
| 提出日時 | 2023-01-19 00:09:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 96 ms / 2,000 ms |
| コード長 | 2,332 bytes |
| コンパイル時間 | 773 ms |
| コンパイル使用メモリ | 78,092 KB |
| 最終ジャッジ日時 | 2025-02-10 04:08:21 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#line 1 "test/yukicoder/1601.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/1601"
#include <iostream>
#line 1 "datastructure/range_set.hpp"
#include <cassert>
#include <map>
template <typename T>
struct range_set {
public:
range_set(bool merge_adjacent_segment = true)
: merge_adjacent_segment(merge_adjacent_segment) {
}
void clear() {
mp.clear();
}
size_t size() {
return mp.size();
}
bool is_covered(T l, T r) {
assert(l <= r);
auto it = mp.upper_bound(l);
return it != mp.begin() && std::prev(it)->first <= l &&
r <= std::prev(it)->second;
}
bool is_covered(T p) {
return is_covered(p, p);
}
auto covered_by(T l, T r) {
assert(l <= r);
assert(is_covered(l, r));
return std::prev(mp.upper_bound(l));
}
auto covered_by(T p) {
return covered_by(p, p);
}
void insert(T l, T r) {
assert(l <= r);
auto it_l = mp.upper_bound(l);
auto it_r = mp.upper_bound(r + int(merge_adjacent_segment));
if (it_l != mp.begin()) {
if (std::prev(it_l)->second >= l - int(merge_adjacent_segment)) {
it_l--;
}
}
for (auto it = it_l; it != it_r; it = mp.erase(it)) {
l = std::min(l, it->first);
r = std::max(r, it->second);
}
mp[l] = r;
}
void erase(T l, T r) {
assert(l <= r);
auto it_l = mp.upper_bound(l);
auto it_r = mp.upper_bound(r);
if (it_l != mp.begin()) {
if (std::prev(it_l)->second >= l) {
it_l--;
}
}
int nl = std::min(l, it_l->first);
int nr = std::max(r, std::prev(it_r)->second);
mp.erase(it_l, it_r);
if (nl < l) mp[nl] = l - 1;
if (r < nr) mp[r + 1] = nr;
}
private:
bool merge_adjacent_segment;
std::map<T, T> mp;
};
#line 6 "test/yukicoder/1601.test.cpp"
int main() {
long long d;
int q;
std::cin >> d >> q;
range_set<long long> st;
long long ans = 0;
while (q--) {
long long a, b;
std::cin >> a >> b;
st.insert(a, b);
auto [l, r] = *st.covered_by(a);
ans = std::max(ans, r - l + 1);
std::cout << ans << '\n';
}
}
gyouzasushi