結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2021-10-21 12:30:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,500 bytes |
| コンパイル時間 | 2,862 ms |
| コンパイル使用メモリ | 219,168 KB |
| 最終ジャッジ日時 | 2025-01-25 02:13:34 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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);
}
tuple<ll,ll> 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;
return {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;
ll ans=0;
REP(_,q){
ll a,b;cin>>a>>b;
auto [l,r]=seg.insert(a,b+1);
ans=max(ans,r-l);
cout<<ans<<"\n";
}
}
cureskol