結果
問題 | No.674 n連勤 |
ユーザー |
|
提出日時 | 2024-01-03 15:07:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,268 bytes |
コンパイル時間 | 4,386 ms |
コンパイル使用メモリ | 256,912 KB |
最終ジャッジ日時 | 2025-02-18 16:01:23 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 11 WA * 6 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; }ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); }istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; }ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; }ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); }typedef long long ll;typedef vector<vector<int>> Graph;typedef pair<int, int> pii;typedef pair<ll, ll> pll;#define FOR(i,l,r) for (int i = l;i < (int)(r); i++)#define rep(i,n) for (int i = 0;i < (int)(n); i++)#define all(x) x.begin(), x.end()#define rall(x) x.rbegin(), x.rend()#define my_sort(x) sort(x.begin(), x.end())#define my_max(x) *max_element(all(x))#define my_min(x) *min_element(all(x))template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }const int INF = (1<<30) - 1;const ll LINF = (1LL<<62) - 1;const int MOD = 998244353;const int MOD2 = 1e9+7;const double PI = acos(-1);vector<int> di = {1,0,-1,0};vector<int> dj = {0,1,0,-1};#ifdef LOCAL# include <debug_print.hpp># define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)#else# define debug(...) (static_cast<void>(0))#endif// https://noimi.hatenablog.com/entry/2021/05/02/195143?_ga=2.186800042.36757101.1619952706-2024379568.1619952706// S : 持つデータの型 T : 範囲の型template <class S, class T = int> struct IntervalManager {struct node {T l, r;S x;node(const T &l, const T &r, const S &x) : l(l), r(r), x(x) {}constexpr bool operator<(const node &rhs) const {if(l != rhs.l) return l < rhs.l;return r < rhs.r;}};const S unit;set<node> s;IntervalManager(const S &u = S()) : unit(u) {}IntervalManager(const vector<T> &a) {vector<node> setter;for(int l = 0; l < a.size(); l++) {int r = l;for(; r < a.size() and a[l] == a[r]; r++) {}setter.emplace_back(l, r, a[l]);l = r - 1;}s = set<node>(all(setter));}// x を含んだセグメントのイテレータを返すtypename set<node>::iterator getIt(const T &x) {auto it = s.upper_bound(node(x, numeric_limits<T>::max(), 0));if(it == begin(s)) return end(s);it = prev(it);if(it->l <= x and x < it->r) return it;return end(s);}// x を含んだセグメントの情報を持ってくるnode getSeg(const T &x) {auto it = getIt(x);if(it != end(s)) return *it;return node(x, x + 1, unit);}// x 以上をはじめて含むセグメントの iterator が帰ってくるtypename set<node>::iterator nextIt(const T &x) {auto it = s.upper_bound(node(x, numeric_limits<T>::max(), 0));if(it == begin(s)) return it;return prev(it);}// x に設定されてる値を取得S get(const T &x) {auto it = getIt(x);if(it != end(s)) return it->x;return unit;}S operator[](T k) const { return get(k); }// [l, r) := x を set するときに消える区間加える区間ごとに関数を呼び出す// ただし、内包, 結合される [L, r) := x の区間も一旦消すtemplate <typename ADD, typename DEL> void update(T l, T r, const S &x, const ADD &add, const DEL &del) {auto it = s.lower_bound(node{l, 0, x});while(it != end(s) and it->l <= r) {if(it->l == r) {if(it->x == x) {del(r, it->r, x);r = it->r, it = s.erase(it);}break;}if(it->r <= r) {del(it->l, it->r, it->x);it = s.erase(it);} else {if(it->x == x) {r = it->r;del(it->l, it->r, it->x);it = s.erase(it);} else {del(it->l, r, it->x);node n = *it;it = s.erase(it);it = s.emplace_hint(it, r, n.r, n.x);}}}if(it != begin(s)) {it = prev(it);if(it->r == l) {if(it->x == x) {del(it->l, it->r, it->x);l = it->l;it = s.erase(it);}} else if(l < it->r) {if(it->x == x) {del(it->l, it->r, it->x);l = min(l, it->l);r = max(r, it->r);it = s.erase(it);} else {if(r < it->r) {it = s.emplace_hint(next(it), r, it->r, it->x);it = prev(it);}del(l, min(r, it->r), it->x);node n = *it;it = s.erase(it);it = s.emplace_hint(it, n.l, l, n.x);}}}if(it != end(s)) it = next(it);debug(l, r);add(l, r, x);s.emplace_hint(it, l, r, x);}void update(T l, T r, const S &x) {update(l, r, x, [](T, T, S) {}, [](T, T, S) {});}void show() {for(auto e : s) {cerr << "("<< "[" << e.l << ", " << e.r << "): " << e.x << ") ";}cerr << endl;}};int main(){cin.tie(0);ios_base::sync_with_stdio(false);ll D, Q; cin >> D >> Q;IntervalManager<ll,ll> IM;ll ans = 0;auto ADD = [&](ll l, ll r, ll x){chmax(ans, r - l);};rep(i,Q){int A, B; cin >> A >> B;IM.update(A, B + 1, 1, ADD, ADD);cout << ans << endl;}}