結果

問題 No.674 n連勤
ユーザー idat_50meidat_50me
提出日時 2023-11-27 15:11:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,865 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 209,604 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-27 15:11:27
合計ジャッジ時間 4,656 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifndef call_include
#define call_include
#include <bits/stdc++.h>
using namespace std;
#endif

template<typename T> struct SegmentSet {
private:
	map<T, T> mp;

public:
	SegmentSet() : mp(){};

	void insert(T x) {
		insert(x, x);
	}
	void insert(T l, T r) {
		assert(l <= r);
		auto itr_l = mp.upper_bound(l), itr_r = mp.upper_bound(r + 1);
		if(itr_l != mp.begin()) {
			if((--itr_l)->second < l - 1) itr_l++;
		}

		if(itr_l != itr_r) {
			l = std::min(l, itr_l->first);
			r = std::max(r, prev(itr_r)->second);
			mp.erase(itr_l, itr_r);
		}

		mp[l] = r;
	}

	void erase(T x) {
		erase(x, x);
	}
	void erase(T l, T r) {
		assert(l <= r);
		auto itr_l = mp.upper_bound(l), itr_r = mp.upper_bound(r);
		if(itr_l != mp.begin()) {
			if((--itr_l)->second < l) itr_l++;
		}

		if(itr_l == itr_r) return;

		T tmp_l = itr_l->first, tmp_r = prev(itr_r)->second;
		mp.erase(itr_l, itr_r);
		if(tmp_l < l) mp[tmp_l] = l - 1;
		if(r < tmp_r) mp[r + 1] = tmp_r;
	}

	pair<T, T> get_seg(T x) {
		auto itr = mp.upper_bound(x);
		if(itr == mp.begin() or (--itr)->second < x) return pair<T, T>(0, -1);
		return pair<T, T>(itr->first, itr->second);
	}

	T min() {
		return mp.begin()->first;
	}

	T max() {
		return mp.rbegin()->second;
	}

	T mex(T x = 0) {
		pair<T, T> p = get_seg(x);
		if(p.first > p.second) return x;
		return p.second + 1;
	}

	bool same(T x, T y) {
		pair<T, T> p = get_seg(x);
		return p.first <= p.second and p.first <= y and y <= p.second;
	}

	int size() {
		return int(mp.size());
	}

	void out() {
		for(auto [l, r] : mp) cout << "[" << l << ", " << r << "]\n";
	}
};

int main() {
	long long D;
	int Q;
	SegmentSet<long long> s;

	cin >> D >> Q;

	long long ans = 0;
	for(int i = 0; i < Q; i++) {
		long long A, B;
		cin >> A >> B;
		s.insert(A, B);
		auto p = s.get_seg(A);
		ans = max(ans, p.second - p.first + 1);
		cout << ans << endl;
	}
}
0