結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2021-10-21 12:27:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,608 bytes |
| コンパイル時間 | 1,897 ms |
| コンパイル使用メモリ | 186,340 KB |
| 実行使用メモリ | 13,756 KB |
| 最終ジャッジ日時 | 2024-09-21 07:34:20 |
| 合計ジャッジ時間 | 6,255 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 1 -- * 3 |
ソースコード
#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);
}
void 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;
}
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;
auto query=[&](){
ll res=0;
auto it=seg.mp.begin();
while(it!=seg.mp.end()){
res=max(res,(it->second)-(it->first));
++it;
}
return res;
};
REP(_,q){
ll a,b;cin>>a>>b;
seg.insert(a,b+1);
cout<<query()<<"\n";
}
}
cureskol