結果

問題 No.674 n連勤
ユーザー konbu1610
提出日時 2024-11-19 09:28:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 4,383 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 178,976 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-19 09:28:38
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
template<typename T> T chmax(T& a, const T& b) { return a = (a > b ? a : b); }
template<typename T> T chmin(T& a, const T& b) { return a = (a < b ? a : b); }
void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; }
// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x)
#define dumpL(x)
#define LINE
#define LINEL
#define dumpV(v)
#define dumpVL(v)
#define STOP assert(false)
#endif
#define mp make_pair
namespace std {
template<class S, class T>
ostream& operator <<(ostream& out, const pair<S, T>& a) {
out << '(' << a.first << ", " << a.second << ')';
return out;
}
}
// hankaikukan
template<typename T>
struct RangeSet {
using P = pair<T, T>;
set<P> st;
const T INF;
const P NG;
RangeSet() :INF(numeric_limits<T>::max() / 2), NG(P(INF, INF)) {}
bool isIntersect(const T& x, const P& p) {
return p.first <= x && x < p.second;
}
bool isIntersect(const P& p1, const P& p2) {
if (p1.first < p2.first) return isIntersect(p2.first, p1);
else return isIntersect(p1.first, p2);
}
bool isExist(const T& x) {
auto it = st.lower_bound({ x, INF });
if (it == st.begin()) return false;
--it;
return isIntersect(x, *it);
}
P get(const T& x) {
if (!isExist(x)) return NG;
auto it = st.lower_bound({ x, INF });
--it;
return *it;
}
P merge_range(const P& p1, const P& p2) {
return P{ min(p1.first, p2.first), max(p1.second, p2.second) };
}
void add(const P& p) {
P add = p;
{
auto tmp = get(p.first - 1);
if (tmp != NG) {
add = merge_range(add, tmp);
st.erase(tmp);
}
}
{
auto tmp = get(p.first);
if (tmp != NG) {
add = merge_range(add, tmp);
st.erase(tmp);
}
}
{
auto tmp = get(p.second - 1);
if (tmp != NG) {
add = merge_range(add, tmp);
st.erase(tmp);
}
}
{
auto tmp = get(p.second);
if (tmp != NG) {
add = merge_range(add, tmp);
st.erase(tmp);
}
}
erase(add);
st.insert(add);
}
void add(const T& x) {
add(P{ x, x + 1 });
}
void erase(const P& p) {
if (st.empty())return;
auto it = st.lower_bound({ p.first, INF });
if (it == st.begin()) {
if (!isIntersect(p, *it)) return;
}
else {
--it;
if (!isIntersect(p, *it)) ++it;
}
dumpL(*it);
while (it != st.end() && isIntersect(p, *it)) {
auto erase_p = *it;
if (erase_p.first < p.first) st.emplace(erase_p.first, p.first);
if (p.second < erase_p.second) st.emplace(p.second, erase_p.second);
dumpL(erase_p);
st.erase(erase_p);
it = st.upper_bound(erase_p);
}
}
void erase(const T& x) {
erase({ x, x + 1 });
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll d, q;
cin >> d >> q;
RangeSet<ll> rs;
ll ans = 0;
rep(_, q) {
ll a, b;
cin >> a >> b;
rs.add({ a, b + 1 });
dump(a); dumpL(b + 1);
dumpVL(rs.st);
auto p = rs.get(a);
chmax(ans, p.second - p.first);
cout << ans << '\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0