結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-08-05 16:19:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 3,521 bytes |
| コンパイル時間 | 3,014 ms |
| コンパイル使用メモリ | 254,196 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-08-05 16:20:00 |
| 合計ジャッジ時間 | 4,643 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++)
#define all(v) v.begin(),v.end()
#define len(v) ((ll)v.size())
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;
}
//[l,r)を管理(整数)
//番兵からはみ出すと壊れるので注意
//adjacent_mergeをTrueにすると[l,c)と[c,r)をマージする
//insert/eraseはそれぞれ増えた量/減った量を返す
//size,getは番兵を含まない
template<class T> struct interval_set{
const T T_INF=numeric_limits<T>::max()/2;
map<T,T> mp;
T sum=0;
bool adjacent_merge;
interval_set(bool adjacent_merge_):sum(0),adjacent_merge(adjacent_merge_){
mp[-T_INF]=-T_INF;
mp[T_INF]=T_INF;
}
bool covered(T l,T r){ //[l,r)
assert(l<=r);
if(l==r) return true;
auto itr=prev(mp.upper_bound(l));
return itr->first<=l&&r<=itr->second;
}
bool covered(T x){
return covered(x,x+1);
}
pair<T,T> covered_by(T l,T r){ //[l,r)
assert(l<=r);
if(l==r) return {T_INF,T_INF};
auto itr=prev(mp.upper_bound(l));
if(itr->first<=l&&r<=itr->second) return *itr;
return {-T_INF,-T_INF};
}
pair<T,T> covered_by(T x){
return covered_by(x,x+1);
}
T insert(T l,T r){ //[l,r)
assert(l<=r);
if(l==r) return 0;
auto itrl=mp.lower_bound(l),itrr=mp.lower_bound(r+adjacent_merge);
if(l<prev(itrl)->second+adjacent_merge) itrl--;
l=min(l,itrl->first);
r=max(r,prev(itrr)->second);
T ret=r-l;
for(auto itr=itrl;itr!=itrr;itr++) ret-=itr->second-itr->first;
mp.erase(itrl,itrr);
mp[l]=r;
sum+=ret;
return ret;
}
T insert(T x){
return insert(x,x+1);
}
T erase(T l,T r){ //[l,r)
assert(l<=r);
if(l==r) return 0;
auto itrl=mp.lower_bound(l),itrr=mp.lower_bound(r);
if(l<prev(itrl)->second) itrl--;
T x=min(l,itrl->first);
T y=max(r,prev(itrr)->second);
T ret=0;
for(auto itr=itrl;itr!=itrr;itr++) ret+=itr->second-itr->first;
mp.erase(itrl,itrr);
if(x<l){
mp[x]=l;
ret-=l-x;
}
if(r<y){
mp[r]=y;
ret-=y-r;
}
sum-=ret;
return ret;
}
T erase(T x){
return erase(x,x+1);
}
int size(){
return (int)mp.size()-2;
}
T mex(T x=0){
auto itr=prev(mp.upper_bound(x));
if(itr->first<=x&&x<itr->second) return itr->second;
return x;
}
vector<pair<T,T>> get(){
vector<pair<T,T>> ret;
for(auto [l,r]:mp){
if(abs(l)==T_INF) continue;
ret.emplace_back(l,r);
}
return ret;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll d,q;
cin >> d >> q;
interval_set<ll> st(true);
ll ans=0;
while(q--){
ll a,b;
cin >> a >> b;
b++;
st.insert(a,b);
auto [l,r]=st.covered_by(a);
chmax(ans,r-l);
cout << ans << '\n';
}
}
FplusFplusF