結果

問題 No.686 Uncertain LIS
ユーザー shadowYYHshadowYYH
提出日時 2023-12-25 11:28:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 3,665 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 171,072 KB
実行使用メモリ 10,616 KB
最終ジャッジ日時 2023-12-25 11:28:57
合計ジャッジ時間 6,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,288 KB
testcase_01 AC 5 ms
8,288 KB
testcase_02 AC 5 ms
8,288 KB
testcase_03 AC 5 ms
8,288 KB
testcase_04 AC 4 ms
8,288 KB
testcase_05 AC 5 ms
8,288 KB
testcase_06 AC 5 ms
8,288 KB
testcase_07 AC 5 ms
8,288 KB
testcase_08 AC 5 ms
8,288 KB
testcase_09 AC 202 ms
10,476 KB
testcase_10 AC 192 ms
10,428 KB
testcase_11 AC 126 ms
10,336 KB
testcase_12 AC 10 ms
8,288 KB
testcase_13 AC 69 ms
10,336 KB
testcase_14 AC 52 ms
10,336 KB
testcase_15 AC 35 ms
10,336 KB
testcase_16 AC 86 ms
10,336 KB
testcase_17 AC 264 ms
10,616 KB
testcase_18 AC 233 ms
10,616 KB
testcase_19 AC 227 ms
10,616 KB
testcase_20 AC 110 ms
10,336 KB
testcase_21 AC 111 ms
10,336 KB
testcase_22 AC 45 ms
10,336 KB
testcase_23 AC 45 ms
10,336 KB
testcase_24 AC 148 ms
10,616 KB
testcase_25 AC 151 ms
10,616 KB
testcase_26 AC 76 ms
10,344 KB
testcase_27 AC 191 ms
10,616 KB
testcase_28 AC 192 ms
10,616 KB
testcase_29 AC 201 ms
10,616 KB
testcase_30 AC 198 ms
10,616 KB
testcase_31 AC 5 ms
8,288 KB
testcase_32 AC 73 ms
10,616 KB
testcase_33 AC 89 ms
10,336 KB
testcase_34 AC 235 ms
10,616 KB
testcase_35 AC 243 ms
10,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define For(x, y, z) for (int x = y, x##E = z; x <= x##E; ++x)
#define Rof(x, y, z) for (int x = y, x##E = z; x >= x##E; --x)
#define Eor(u) for (int i = head[u]; i; i = nxt[i])
#define SZ(x) (int(x.size()))
#define pb push_back

using namespace std;
using i64 = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f ? -x : x;
}
int __stk[128], __tp;
inline void put(i64 x) {
	if (x < 0) putchar('-'), x = -x;
	do { __stk[++__tp] = x % 10, x /= 10; } while (x);
	while (__tp) putchar(__stk[__tp--] + '0');
}

const int mod = 998244353;
inline int ksm(int x, int y, int res = 1) {
	for ( ; y; y >>= 1, x = 1ll * x * x % mod)
		(y & 1) && (res = 1ll * res * x % mod);
	return res;
}
inline int inv(int x) { return ksm(x, mod - 2); }
inline int gcd(int a, int b) { if (b) while ((a %= b) && (b %= a)); return a | b; }
inline void add(int &x, int y) { (x += y) >= mod && (x -= mod); }
inline void Min(int &x, int y) { (y < x) && (x = y); }
inline void Max(int &x, int y) { (y > x) && (x = y); }

const int N = 2e6 + 1000;

namespace FHQ {
    mt19937 R(114514);
    #define ls(x) (t[x].ls)
    #define rs(x) (t[x].rs)
    struct node { int ls, rs, siz, w, tag, rnd; }t[N];
    int num, root, a, b, c, d;
    void pushup(int x) { t[x].siz = t[ls(x)].siz + t[rs(x)].siz + 1; }
    void update(int x, int v) { if (x) t[x].w += v, t[x].tag += v;}
    void pushdown(int x) { if (t[x].tag) update(ls(x), t[x].tag), update(rs(x), t[x].tag), t[x].tag = 0; }
    int New(int x) { return t[++num] = {0, 0, 1, x, 0, (int)R()}, num; }
    int merge(int x, int y) {
        if (!x || !y) return x | y; ;pushdown(x), pushdown(y);
        if (t[x].rnd < t[y].rnd) return rs(x) = merge(rs(x), y), pushup(x), x;
        return ls(y) = merge(x, ls(y)), pushup(y), y;
    }
    void split(int x, int k, int &a, int &b) {
        if (!x) return a = b = 0, void(); ;pushdown(x);
        if (t[ls(x)].siz >= k) b = x, split(ls(x), k, a, ls(b));
        else a = x, split(rs(x), k - t[ls(x)].siz - 1, rs(a), b);;pushup(x);
    }
    int build(int l, int r) {  if (l > r) return 0;
        int mid = (l + r) >> 1, x = New(0);
        if (l == r) return x; ls(x) = build(l, mid - 1);
        rs(x) = build(mid + 1, r), pushup(x); return x;
    }
    int get_mi(int x) { if (!x) return 0; while (pushdown(x), ls(x)) x = ls(x); return t[x].w; }
    int get_ma(int x) { if (!x) return 0; while (pushdown(x), rs(x)) x = rs(x); return t[x].w; }
    void modify(int x, int v) {
        while (x) {  pushdown(x);
            if (t[x].w < v) update(ls(x), 1), 
                t[x].w += 1, x = rs(x); 
            else x = ls(x);
        }
    }

    void change(int l, int r) {
        split(root, r, b, c), split(b, l - 2, a, b);
        if (l == 1) {
            split(b, t[b].siz - 1, b, d), b = merge(New(0), b), update(b, 1);
            a = merge(a, b), modify(c, get_ma(b)), root = merge(a, c);
        } else {
            split(b, t[b].siz - 1, b, d), d = New(get_mi(b)), update(b, 1);
            a = merge(a, merge(d, b)), modify(c, get_ma(b)), root = merge(a, c);
        }
    }
    
}

signed main() {
	// freopen("lis.in", "r", stdin);
	// freopen("lis2.out", "w", stdout);

    int n = read(); FHQ::root = FHQ::build(1, 1e5);
    while (n--) { int l = read(), r = read(); FHQ::change(l, r); }
    cout << FHQ::get_ma(FHQ::root);
	return 0;
}
0