結果

問題 No.674 n連勤
ユーザー cureskolcureskol
提出日時 2021-10-21 12:27:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,608 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 186,840 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 06:24:44
合計ジャッジ時間 6,491 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n-1);i>=0;i--)
#define ALL(v) v.begin(),v.end()

using ll=long long;
struct SegmentMap{
  map<ll,ll> mp;//mp[l]=r:[l,r)
  //[l,m) [m,r) は[l,r)になる 連続する黒の区間を持つみたいなイメージ
  const ll LINF=4e18;

  SegmentMap(){
    mp[-LINF]=-LINF;
    mp[LINF]=LINF;
  }

  inline auto get_it(ll a){//aを含む[l,r)のiterator
    auto it=--mp.upper_bound(a);
    if(a<(it->second))return it;
    return mp.end();
  }

  tuple<ll,ll> get(ll a){
    auto it=get_it(a);
    if(it==mp.end())return {LINF,-LINF};
    return {it->first,it->second};
  }

  bool same(ll a,ll b){
    auto it=get_it(a);
    return it!=mp.end() && (it->first)<=b && b<(it->second);
  }

  void insert(ll l,ll r){//[l,r)を挿入
    auto it=--mp.upper_bound(l);
    if((it->second)>=l)l=it->first;
    else ++it;
    while((it->first)<=r){
      r=max(r,it->second);
      it=mp.erase(it);
    }
    mp[l]=r;
  }

  void remove(ll l,ll r){//[l,r)と共通部分を持つ区間全削除
    auto it=--mp.upper_bound(l);
    if((it->second)<=l)++it;
    while((it->first)<r)it=mp.erase(it);
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll d,q;cin>>d>>q;
  SegmentMap seg;
  auto query=[&](){
    ll res=0;
    auto it=seg.mp.begin();
    while(it!=seg.mp.end()){
      res=max(res,(it->second)-(it->first));
      ++it;
    }
    return res;
  };
  REP(_,q){
    ll a,b;cin>>a>>b;
    seg.insert(a,b+1);
    cout<<query()<<"\n";
  }
}
0