結果

問題 No.674 n連勤
ユーザー simansiman
提出日時 2023-05-17 15:57:21
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 1,698 ms
コンパイル使用メモリ 108,240 KB
実行使用メモリ 9,212 KB
最終ジャッジ日時 2023-08-21 19:34:21
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 67 ms
4,380 KB
testcase_14 AC 123 ms
9,212 KB
testcase_15 AC 95 ms
6,752 KB
testcase_16 AC 139 ms
9,148 KB
testcase_17 AC 135 ms
9,184 KB
testcase_18 AC 112 ms
6,924 KB
testcase_19 AC 126 ms
9,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  ll D, Q;
  cin >> D >> Q;

  vector<ll> A(Q);
  vector<ll> B(Q);
  set<ll> S;

  for (int i = 0; i < Q; ++i) {
    cin >> A[i] >> B[i];

    S.insert(A[i] - 1);
    S.insert(A[i]);
    S.insert(B[i]);
    S.insert(B[i] + 1);
  }

  ll ans = 0;

  for (int i = 0; i < Q; ++i) {
    ll a = A[i];
    ll b = B[i];

    while (true) {
      auto it = S.lower_bound(a);
      if (*it > b) break;

      S.erase(*it);
    }

    auto it = S.lower_bound(a);
    ll end_at = *it;
    --it;
    ll start_at = *it;

    // fprintf(stderr, "(%lld, %lld)\n", start_at, end_at);
    ans = max(ans, end_at - start_at - 1);
    cout << ans << endl;
  }

  return 0;
}
0