結果

問題 No.674 n連勤
ユーザー CyanmondCyanmond
提出日時 2020-10-25 17:52:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,919 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 122,476 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 02:08:24
合計ジャッジ時間 3,456 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 RE -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 64 ms
4,380 KB
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#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<signed, signed> {
private:
	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(signed p) const {
		auto it = upper_bound(p);
		if (it == begin() || (--it)->second < p) return end();
		return it;
	}
	// insert segment [l, r]
	void insert(signed l, signed 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(signed l, signed r) {
		auto itl = upper_bound(l), itr = upper_bound(r);
		if (itl != begin()) {
			if ((--itl)->second < l) ++itl;
		}
		if (itl == itr) return;
		int 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(signed p, signed 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;
}
0