結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
chlo
|
| 提出日時 | 2019-12-17 10:25:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 2,000 ms |
| コード長 | 2,794 bytes |
| コンパイル時間 | 1,527 ms |
| コンパイル使用メモリ | 178,068 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 21:13:51 |
| 合計ジャッジ時間 | 3,370 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }
template <bool merge_adjacent>
class SectionUnion {
public:
map<long long, long long> sec;
SectionUnion(void) {}
pair<bool, pair<long long, long long>> get(const long long x) const {
auto itr = sec.lower_bound(x);
return {!(itr == sec.end() && x < itr->second), {itr->second, itr->first}};
}
bool insert(long long l, long long r) {
auto litr = sec.lower_bound(l - merge_adjacent), ritr = sec.lower_bound(r);
if (ritr != sec.end() && r + merge_adjacent >= ritr->second) ++ritr;
const bool exist = litr != ritr;
if (exist) {
l = min(l, litr->second), r = max(r, prev(ritr)->first);
sec.erase(litr, ritr);
}
sec.emplace(r, l);
return exist;
}
bool remove(long long l, long long r, bool involve = false) {
auto litr = sec.lower_bound(l), ritr = sec.lower_bound(r);
if (ritr != sec.end() && r >= ritr->second) ++ritr;
const bool exist = litr != ritr;
if (exist) {
long long ledge = litr->second, redge = prev(ritr)->first;
sec.erase(litr, ritr);
if (!involve) {
if (ledge < l) sec[l - 1] = ledge;
if (r < redge) sec[redge] = r + 1;
}
}
return exist;
}
bool same(long long a, long long b) const {
if (b < a) swap(a, b);
auto itr = sec.lower_bound(b);
return itr != sec.end() && itr->second <= a;
}
void clear(void) { sec.clear(); }
bool empty(void) const { return sec.empty(); }
int size(void) const { return sec.size(); }
};
int main(void) {
lint d, q;
cin >> d >> q;
vector<pair<lint, lint>> ab(q);
rep (i, q) cin >> ab[i].first >> ab[i].second;
SectionUnion<true> su;
lint maxi = 0;
vector<lint> ans(q + 1);
rep (i, q) {
su.insert(ab[i].first, ab[i].second);
auto p = su.get(ab[i].first).second;
ans[i + 1] = max(ans[i], p.second - p.first + 1);
}
rep1 (i, q) cout << ans[i] << endl;
return 0;
}
chlo