結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
seica_at_se
|
| 提出日時 | 2018-04-14 18:10:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,034 bytes |
| コンパイル時間 | 1,701 ms |
| コンパイル使用メモリ | 174,572 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 22:31:32 |
| 合計ジャッジ時間 | 3,183 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265359
typedef long long ll;
typedef pair<ll,ll> P;
template <typename T>
class SectionManagement : public std::map<T,T> {
private:
// if merge [l, c] and [c+1, r], set flagToMergeAdjacentSegment to true
bool AdjacentMarge;
public:
SectionManagement(bool flag):AdjacentMarge(flag){}
void print(){
cout << "print SectionManagement" << endl;
for(auto it = this->begin();it != this->end();it++){
cout << (it->first) << ' ' << (it->second) << endl;
}
cout << "end print" << endl;
}
//該当の区間を得る、なければend()
typename std::map<T, T>::const_iterator get(T p) const{
auto it = this->upper_bound(p);
if (it == this->begin() || (--it)->second < p) return this->end();
return it;
}
//挿入、被る所はひとつにまとめる。
void insert(T l,T r){
if(this->size() == 0){
(*this)[l] = r;
// cout << "!" << endl;
return;
}
auto it = this->upper_bound(l);
//cout << "upper " << (it->first) << ' ' << (it->second) << endl;
if(it == this->begin() && r + AdjacentMarge< it->first){
(*this)[l] = r;
// cout << "!!" << endl;
return;
}
if(it != this->begin() && r + AdjacentMarge < it->first && l > std::prev(it)->second + AdjacentMarge){
(*this)[l] = r;
// cout << "!!!" << endl;
return;
}
auto itl = it;
//cout << "prev " << (std::prev(it)->first) << ' ' << (std::prev(it)->second) << endl;
//cout << std::prev(it)->second + AdjacentMarge << endl;
if(it != this->begin() && std::prev(it)->second + AdjacentMarge >= l){
--itl;
l = min(l,itl->first);
}
while(it != this->end() && it->second <= r){
it++;
}
if(it->first > r + AdjacentMarge)--it;
if(it != this->end())r = max(r,it->second);
//cout << "l " << (itl->first) << ' ' << (itl->second) << endl;
//cout << "r " << (it->first) << ' ' << (it->second) << endl;
if(it != this->end())it++;
this->erase(itl,it);
(*this)[l] = r;
}
//同じ区間にあるか
bool same(T p, T q) const {
const auto it = get(p);
return it != this->end() && it->first <= q && q <= it->second;
}
};
int main()
{
SectionManagement<ll> mp(true);
ll d,q;cin >> d >> q;
ll ans = 0;
REP(_,q){
ll a,b;cin >> a >> b;
mp.insert(a,b);
auto it = mp.get(a);
ans = max(ans,it->second - it->first + 1);
cout << ans << endl;
//mp.print();
}
return 0;
}
seica_at_se