結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-22 10:36:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 4,857 bytes |
| コンパイル時間 | 1,662 ms |
| コンパイル使用メモリ | 175,016 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-22 10:36:57 |
| 合計ジャッジ時間 | 2,862 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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); }
// #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 {
map<T, T> mp;
using P = pair<T, T>;
const T INF;
const P NG;
RangeSet() :INF(numeric_limits<T>::max() / 2), NG(INF, INF) {}
bool intersect(const T& x, const T& l, const T& r) {
return l <= x && x <= r;
}
bool intersect(const T& l, const T& r, const T& L, const T& R) {
return intersect(l, L, R) || intersect(L, l, r);
}
bool intersect(const T& x, const P& p) {
return intersect(x, p.first, p.second);
}
bool intersect(const P& p1, const P& p2) {
return intersect(p1.first, p1.second, p2.first, p2.second);
}
P merged_range(const P& p1, const P& p2) {
return P{ min(p1.first, p2.first), max(p1.second, p2.second) };
}
P get(const T& x) {
auto it = mp.upper_bound(x);
if (it != mp.begin()) {
--it;
if (x < it->second) return *it;
}
return NG;
}
void add(const P& p) {
T l = p.first, r = p.second;
auto it = mp.upper_bound(l);
if (it != mp.begin()) --it;
while (it != mp.end() && it->first <= r) {
if (intersect(l, r, it->first, it->second)) {
chmin(l, it->first);
chmax(r, it->second);
it = mp.erase(it);
}
else ++it;
}
mp[l] = r;
}
void add(const T& x) {
add(P{ x, x + 1 });
}
void erase(const P& p) {
T l = p.first, r = p.second;
auto it = mp.upper_bound(l);
if (it != mp.begin()) --it;
vector<P> adds;
while (it != mp.end() && it->first <= r) {
if (intersect(l, r, it->first, it->second)) {
if (it->first < l) adds.emplace_back(it->first, l);
if (r < it->second) adds.emplace_back(r, it->second);
it = mp.erase(it);
}
else ++it;
}
for (auto&& a : adds) mp[a.first] = a.second;
}
void erase(const T& x) {
erase({ x, x + 1 });
}
int count_intersect(const P& p) {
T l = p.first, r = p.second;
int res = 0;
auto it = mp.upper_bound(l);
if (it != mp.begin()) --it;
while (it != mp.end() && it->first < r) {
if ((l <= it->first && it->first < r) || (it->first <= l && l < it->second)) res++;
++it;
}
return res;
};
};
struct UF { //O(loga(n))
int n;
int m;
vi d, r;
UF(int n) : n(n), m(n), d(n, -1), r(n, 0) {};
int root(int i) {
if (d[i] < 0) return i;
return d[i] = root(d[i]);
}
bool same(int x, int y) {
return root(x) == root(y);
}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (r[x] < r[y]) swap(x, y);
else if (r[x] == r[y]) r[x]++;
d[x] += d[y];
d[y] = x;
--m;
return true;
}
int size(int i) {
return -d[root(i)];
}
int size() {
return m;
}
};
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;
b++;
rs.add({ a, b });
dump(a); dumpL(b);
dumpVL(rs.mp);
auto p = rs.get(a);
chmax(ans, p.second - p.first);
cout << ans << '\n';
}
return 0;
}