結果
問題 | No.674 n連勤 |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-22 03:28:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 4,566 bytes |
コンパイル時間 | 1,942 ms |
コンパイル使用メモリ | 203,240 KB |
最終ジャッジ日時 | 2025-01-19 03:19:29 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;#define FOR(i,m,n) for(int i=(m);i<(n);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()using ll = long long;constexpr int INF = 0x3f3f3f3f;constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;constexpr double EPS = 1e-8;constexpr int MOD = 1000000007;// constexpr int MOD = 998244353;constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }struct IOSetup {IOSetup() {std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);std::cout << fixed << setprecision(20);}} iosetup;template <typename T>struct SetManagedByInterval {std::set<std::pair<T, T>> interval{{std::numeric_limits<T>::lowest(), std::numeric_limits<T>::lowest()},{std::numeric_limits<T>::max(), std::numeric_limits<T>::max()},};bool contains(T x) const { return contains(x, x); }bool contains(T left, T right) const {auto it = interval.lower_bound({left, left});if (left < it->first) it = std::prev(it);return it->first <= left && right <= it->second;}bool erase(T x) {auto it = interval.lower_bound({x, x});if (it->first == x) {T right = it->second;interval.erase(it);if (x + 1 <= right) interval.emplace(x + 1, right);return true;}it = std::prev(it);T left, right; std::tie(left, right) = *it;if (right < x) return false;interval.erase(it);interval.emplace(left, x - 1);if (x + 1 <= right) interval.emplace(x + 1, right);return true;}T erase(T left, T right) {assert(left <= right);auto it = interval.lower_bound({left, left});T res = 0;for (; it->second <= right; it = interval.erase(it)) res += it->second - it->first + 1;if (it->first <= right) {res += right - it->first + 1;T r = it->second;interval.erase(it);it = interval.emplace(right + 1, r).first;}if (left <= std::prev(it)->second) {it = std::prev(it);res += it->second - left + 1;T l = it->first;interval.erase(it);interval.emplace(l, left - 1);}return res;}bool insert(T x) {auto it = interval.lower_bound({x, x});if (it->first == x || x <= std::prev(it)->second) return false;T left = x, right = x;if (x + 1 == it->first) {right = it->second;it = interval.erase(it);}if (std::prev(it)->second == x - 1) {it = std::prev(it);left = it->first;interval.erase(it);}interval.emplace(left, right);return true;}T insert(T left, T right) {assert(left <= right);auto it = interval.lower_bound({left, left});if (left <= std::prev(it)->second) {it = std::prev(it);left = it->first;}if (left == it->first && right <= it->second) return 0;T res = 0;for (; it->second <= right; it = interval.erase(it)) res -= it->second - it->first + 1;if (it->first <= right) {res -= it->second - it->first + 1;right = it->second;it = interval.erase(it);}res += right - left + 1;if (right + 1 == it->first) {right = it->second;it = interval.erase(it);}if (std::prev(it)->second == left - 1) {it = std::prev(it);left = it->first;interval.erase(it);}interval.emplace(left, right);return res;}T mex(T x = 0) const {auto it = interval.lower_bound({x, x});if (x <= std::prev(it)->second) it = std::prev(it);return x < it->first ? x : it->second + 1;}friend std::ostream &operator<<(std::ostream &os, const SetManagedByInterval &st) {if (st.interval.size() == 2) return os;auto it = next(st.interval.begin());while (true) {os << '[' << it->first << ", " << it->second << ']';it = next(it);if (next(it) == st.interval.end()) {break;} else {os << ' ';}}return os;}};int main() {ll d; int q; cin >> d >> q;SetManagedByInterval<ll> st;ll ans = 0;while (q--) {ll a, b; cin >> a >> b;st.insert(a, b);auto [l, r] = *prev(st.interval.lower_bound({a + 1, a + 1}));chmax(ans, r - l + 1);cout << ans << '\n';}return 0;}