結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-25 18:08:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 2,000 ms |
| コード長 | 3,086 bytes |
| コンパイル時間 | 1,331 ms |
| コンパイル使用メモリ | 123,344 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 20:53:58 |
| 合計ジャッジ時間 | 2,633 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma region header
using namespace std;
using lint = long long;
const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, 1, 0, -1 };
const long long INF = 1ll << 60;
const int mod = 1000000007;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define init std::ios::sync_with_stdio(false);std::cin.tie(0);
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return true;
}
return false;
}
#pragma endregion
class SegmentMap : public std::map<long long, long long> {
bool flagToMergeAdjacentSegment;
public:
// if merge [l, c] and [c+1, r], set flagToMergeAdjacentSegment to true
SegmentMap(bool flagToMergeAdjacentSegment) :
flagToMergeAdjacentSegment(flagToMergeAdjacentSegment) {
}
// __exist -> iterator pair(l, r) (contain p)
// noexist -> map.end()
auto get(long long p) const {
auto it = upper_bound(p);
if (it == begin() || (--it)->second < p) return end();
return it;
}
// insert segment [l, r]
void insert(long long l, long long r) {
auto itl = upper_bound(l), itr = upper_bound(r + flagToMergeAdjacentSegment);
if (itl != begin()) {
if ((--itl)->second < l - flagToMergeAdjacentSegment) ++itl;
}
if (itl != itr) {
l = std::min(l, itl->first);
r = std::max(r, std::prev(itr)->second);
erase(itl, itr);
}
(*this)[l] = r;
}
// remove segment [l, r]
void remove(long long l, long long r) {
auto itl = upper_bound(l), itr = upper_bound(r);
if (itl != begin()) {
if ((--itl)->second < l) ++itl;
}
if (itl == itr) return;
long long tl = std::min(l, itl->first), tr = std::max(r, std::prev(itr)->second);
erase(itl, itr);
if (tl < l) (*this)[tl] = l - 1;
if (r < tr) (*this)[r + 1] = tr;
}
// Is p and q in same segment?
bool same(long long p, long long q) const {
const auto&& it = get(p);
return it != end() && it->first <= q && q <= it->second;
}
};
int main(void) {
init;
lint d, q; cin >> d >> q;
SegmentMap s(true);
lint dynamicans = 0;
for (int _ = 0; _ < q; ++_) {
lint a, b; cin >> a >> b;
s.insert(a, b);
auto itr = s.get(a);
chmax(dynamicans, itr->second - itr->first + 1);
cout << dynamicans << endl;
}
return 0;
}