結果

問題 No.674 n連勤
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-15 02:18:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 3,263 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 202,572 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 00:37:04
合計ジャッジ時間 4,269 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 8 ms
5,376 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 73 ms
5,376 KB
testcase_14 AC 78 ms
5,376 KB
testcase_15 AC 73 ms
5,376 KB
testcase_16 AC 92 ms
5,376 KB
testcase_17 AC 93 ms
5,376 KB
testcase_18 AC 84 ms
5,376 KB
testcase_19 AC 79 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Intervals{
	set<pl> st;
	Intervals(){
		st.insert({-INF,-INF});
		st.insert({INF,INF});
	}
	void insert(pl p){//開区間pを挿入し、マージする
		auto x=st.lower_bound(p);x--;
		while(true){
			auto q=*x;
			if((p.first<=q.first&&q.first<=p.second)||(q.first<=p.first&&p.first<=q.second)){
				p.first=min(p.first,q.first);
				p.second=max(p.second,q.second);
				x=st.erase(x);
			}
			else if(q.second<=p.first)x++;
			else break;
		}
		st.insert(p);
	}
	pl get(ll i){//iを含む区間を返す もしそのような区間がなければ、{-INF,INF}を返す
		auto x=st.upper_bound({i,INF});x--;
		if(x->first<=i&&i<x->second)return *x;
		else return make_pair(-INF,INF);
	}
	bool same(ll l,ll r){//lとrが同じ区間に属しているか
    if(get(l).first==-INF)return false;
		else return get(l)==get(r);
	}
	void split(pl p){//区間pをちょうど取り除く 該当する区間がない場合は何も起こらない [x,x)を入力すると、そこで区間を分割するが、幅0の区間は捨てられる。
		auto x=st.lower_bound(p);x--;
		vpl cand;
		while(true){
			auto q=*x;
			if((p.first<=q.first&&q.first<=p.second)||(q.first<=p.first&&p.first<=q.second)){
				if(q.first<=p.first){
					if(q.first!=p.first)cand.push_back({q.first,p.first});
				}
				if(p.second<=q.second){
					if(p.second!=q.second)cand.push_back({p.second,q.second});
				}
				x=st.erase(x);
			}
			else if(q.second<p.first)x++;
			else break;
		}
		for(auto q:cand)st.insert(q);
	}
	void view(){
		for(auto p:st){
			if(abs(p.first)==INF)continue;
			cout << "[" <<p.first <<"," << p.second <<"), ";
		}
		cout << endl;
	}
	ll mex(pl p){//区間pに含まれ、stに含まれないようなiのうち、もっとも左の座標 区間pが全て埋まっているなら、INFを返す
		ll left=p.first;
		while(left<p.second){
			auto to=get(left);
			if(to.first==-INF)break;
			left=to.second;
		}
		if(left<p.second)return left;
		else return INF;
	}
};

int main(){
  ll d,q;cin >> d >> q;
  Intervals iv;
  ll ans=0;
  while(q--){
    ll l,r;cin >> l >> r;
    iv.insert({l,r+1});
    auto p=iv.get(l);
    chmax(ans,p.second-p.first);
    cout << ans <<endl;
  }
}      

0