結果

問題 No.686 Uncertain LIS
ユーザー konjakujellykonjakujelly
提出日時 2023-12-25 11:03:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,614 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 170,780 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-25 11:03:46
合計ジャッジ時間 7,249 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 25 ms
6,676 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 3 ms
6,676 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int findrk(int)':
main.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
   76 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 1e5 + 10, M = 1e5;

int n, rt, cnt, top;
int t[N][2], fa[N], siz[N], s[N], tag[N], stk[N];

void update(int x) { siz[x] = siz[t[x][0]] + siz[t[x][1]] + 1; }

void pushup(int x, int k) { tag[x] += k, s[x] += k; }
void pushdown(int x) { pushup(t[x][0], tag[x]), pushup(t[x][1], tag[x]), tag[x] = 0; }

int build(int l, int r) {
    if (l > r) return 0; int mid = (l + r) >> 1, x = ++cnt;
    t[x][0] = build(l, mid - 1), t[x][1] = build(mid + 1, r);
    return update(x), fa[t[x][0]] = fa[t[x][1]] = x;
}

int get(int x) { return t[fa[x]][1] == x; }

void rotate(int x) {
    int f1 = fa[x], f2 = fa[f1], k = get(x);
    if (f2) t[f2][get(f1)] = x; fa[x] = f2;
    t[f1][k] = t[x][!k], fa[t[f1][k]] = f1;
    t[x][!k] = f1, fa[f1] = x;
    update(f1), update(x);
}

void splay(int x, int to = 0) {
    if (x == to) return;
    // int p = stk[top = 1] = x;
    // while (fa[p] ^ to) stk[++top] = p = fa[p];
    // while (top) pushdown(stk[top--]);
    for (int f; (f = fa[x]) ^ to; rotate(x)) 
        if (fa[f] ^ to) rotate(get(x) == get(f) ? f : x);
    if (!to) rt = x; 
}

int findrk(int k) {
    int x = rt;
    while (x) {
        if (k <= siz[t[x][0]]) x = t[x][0];
        else {
            k -= siz[t[x][0]] + 1;
            if (!k) return x;
            x = t[x][1];
        }
    }
}

void split(int l, int r) { splay(findrk(l)), splay(findrk(r + 3), rt); }

bool edmer;
signed main() {
	// freopen("Yukicoder686.in", "r", stdin);
	// freopen("Yukicoder686.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
	
    n = read(), rt = build(-1, M + 1);
    
    for (int i = 1; i <= n; i++) {
        int l = read(), r = read(), x, y, z;
        split(l, r), x = y = t[t[rt][1]][0];

        while (t[y][0]) pushdown(y), y = t[y][0];
        int val = s[y];

        while (t[x][1]) pushdown(x), x = t[x][1];
        y = fa[x], z = t[x][0], pushdown(x);

        t[y][y != t[rt][1]] = z, fa[z] = y, update(y);
        splay(z ? z : y, t[rt][1]);

        y = t[t[rt][1]][0], pushup(y, 1);

        while (t[y][0]) pushdown(y), y = t[y][0];
        s[x] = val, tag[x] = 0, pushdown(y);

        t[x][0] = 0, siz[x] = 1, t[y][0] = x, fa[x] = y;
        update(y), splay(x, y = t[rt][1]);

        while (t[x][1]) pushdown(x), x = t[x][1];
        if (s[y] < s[x]) {
            int lat = y;
            s[y]++, pushdown(y), y = t[y][1];
            while (y) {
                lat = y, pushdown(y);
                if (s[y] >= s[x]) y = t[y][0];
                else s[y]++, pushup(t[y][0], 1), y = t[y][1];
            }
            splay(lat);
        }
    }

    int x = rt;
    while (t[x][1]) pushdown(x), x = t[x][1];

    write(s[x]);

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 
0