結果

問題 No.674 n連勤
ユーザー 0w1
提出日時 2018-04-14 19:56:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 200,056 KB
最終ジャッジ日時 2025-01-05 10:14:30
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main() {
  ios::sync_with_stdio(false);

  int64_t D;
  int Q;
  cin >> D >> Q;

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

  set<int64_t> pnts;
  for (int i = 0; i < Q; ++i) {
    pnts.emplace(A[i] - 1);
    pnts.emplace(A[i]);
    pnts.emplace(B[i]);
    pnts.emplace(B[i] + 1);
  }

  int64_t ans = 0;
  for (int qi = 0; qi < Q; ++qi) {
    while (true) {
      auto it = pnts.lower_bound(A[qi]);
      if (*it > B[qi]) break;
      pnts.erase(it);
    }
    auto ed = pnts.lower_bound(B[qi]);
    auto st = prev(pnts.lower_bound(B[qi]));
    cout << (ans = max<int64_t>(ans, *ed - *st - 1)) << endl;
  }

  return 0;
}
0