結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-15 02:18:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 3,263 bytes |
| コンパイル時間 | 2,493 ms |
| コンパイル使用メモリ | 202,432 KB |
| 最終ジャッジ日時 | 2025-01-23 22:21:05 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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;
}
}