結果

問題 No.674 n連勤
ユーザー どららどらら
提出日時 2018-04-14 01:41:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 169,532 KB
実行使用メモリ 4,644 KB
最終ジャッジ日時 2023-09-09 04:58:33
合計ジャッジ時間 3,205 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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 69 ms
4,376 KB
testcase_14 AC 74 ms
4,380 KB
testcase_15 AC 69 ms
4,380 KB
testcase_16 AC 83 ms
4,384 KB
testcase_17 AC 83 ms
4,644 KB
testcase_18 AC 74 ms
4,380 KB
testcase_19 AC 72 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct RNG {
  ll l, r;
  bool operator<(const RNG& a) const {
    return r < a.r;
  }
};

class MaxRange {
  ll max_range;
  set<RNG> rngs;
public:
  MaxRange():max_range(0){}

  void add(const RNG& rng){
    ll nl = rng.l, nr = rng.r;
    
    auto bgn = rngs.lower_bound((RNG){nl-1,nl-1});
    auto it = bgn;
    for(; it != rngs.end(); it++){
      if(it->l <= rng.r+1){
        nl = min(nl, it->l);
        nr = max(nr, it->r);
      }else{
        break;
      }
    }
    
    rngs.erase(bgn, it);
    rngs.insert((RNG){nl,nr});
    max_range = max(max_range, nr+1-nl);
  }

  ll get_max(){
    return max_range;
  }
};



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

  MaxRange mr;
  
  rep(i,Q){
    ll A, B;
    cin >> A >> B;
    mr.add((RNG){A,B});
    cout << mr.get_max() << endl;
  }
  
  return 0;
}

0