結果

問題 No.674 n連勤
ユーザー CyanmondCyanmond
提出日時 2020-10-25 18:08:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 3,086 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 122,544 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 02:08:43
合計ジャッジ時間 3,032 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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<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;
}
0