結果

問題 No.674 n連勤
ユーザー KKT89KKT89
提出日時 2020-10-13 20:50:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 204,668 KB
実行使用メモリ 4,524 KB
最終ジャッジ日時 2023-09-28 00:17:14
合計ジャッジ時間 4,293 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 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,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 14 ms
4,384 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 25 ms
4,524 KB
testcase_17 AC 23 ms
4,464 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll d; cin >> d;
    int q; cin >> q;
    set<pair<ll,ll>> st;
    st.insert(make_pair(-2e18,-2e18));
    st.insert(make_pair(2e18,2e18));
    ll res=0;
    while(q--){
        ll a,b; cin >> a >> b; b++;
        auto it=st.lower_bound(make_pair(a,b));
        it--;
        if(it->first<=a and a<=it->second){
            if(it->first>=0)a=min(a,it->first);
            if(it->second<=d)b=max(b,it->second);
            st.erase(it);
        }
        it=st.lower_bound(make_pair(a,b));
        while(1){
            if(a<=it->first and it->first<=b){
                b=max(b,it->second);
                it=st.erase(it);
            }
            else{
                break;
            }
        }
        st.insert(make_pair(a,b));
        res=max(res,b-a);
        printf("%lld\n",res);
    }
}
0