提出 #68169928


ソースコード 拡げる

// #define WANT_LDEBUG
#ifdef LOCAL
#include "D:/C++/include/all.h"
#else
#include <bits/stdc++.h>
#define ldebug(...)
#define cpp_version_ __cplusplus
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define RREP(i, a, b) for (int i = a; i > (b); --i)
#define FOR(i, a, b) for (int i = a; i <= (b); ++i)
#define RFOR(i, a, b) for (int i = a; i >= (b); --i)
#define REPK(i, a, b, k) for (int i = a; i < (b); i += k)
#define RREPK(i, a, b, k) for (int i = a; i > (b); i -= k)
#define FORK(i, a, b, k) for (int i = a; i <= (b); i += k)
#define RFORK(i, a, b, k) for (int i = a; i >= (b); i -= k)
using namespace std;
using bool_t = signed char;
using u32 = unsigned int;
using i64 = long long;
using i128 = __int128;
using u64 = unsigned long long;
using f64 = double;
#define fast_io()                                                              \
    std::ios::sync_with_stdio(false);                                          \
    std::cin.tie(nullptr)
template <typename T, typename U> bool ckmax(T &a, U b) {
    return a < b && (a = b, true);
}
template <typename T, typename U> bool ckmin(T &a, U b) {
    return b < a && (a = b, true);
}
#endif


constexpr int MAXN = 5e5 + 5, LOG_N = 20;
bool hs[MAXN]; //< heavy son
int Q;
array<int, LOG_N> son[MAXN];
i64 len[MAXN], lost[MAXN][LOG_N][2], x[MAXN];
array<int, 2> ch[MAXN];

void solve() {
    len[0] = len[1] = 1;
    cin >> Q;
    son[0].fill(-1);
    son[1].fill(-1);
    FOR(i, 1, Q) {
        int u = i + 1;
        cin >> ch[u][0] >> ch[u][1] >> x[i];
        len[u] = min(len[ch[u][0]] + len[ch[u][1]], static_cast<i64>(1e18));
        hs[u] = (len[ch[u][1]] > len[ch[u][0]]);
        son[u][0] = ch[u][hs[u]];
        ldebug("son[{}] = {}, len = {}\n", u, ch[u][hs[u]], len[u]);
        lost[u][0][!hs[u]] = len[ch[u][!hs[u]]];
        // ldebug("lost[{}][0][{}] = {}\n", u, !hs[u], lost[u][0][!hs[u]]);
        REP(j, 1, LOG_N) {
            if (son[u][j - 1] == -1) {
                son[u][j] = -1;
                continue;
            }
            son[u][j] = son[son[u][j - 1]][j - 1];
            REP(k, 0, 2) {
                lost[u][j][k] = lost[u][j - 1][k] + lost[son[u][j - 1]][j - 1][k];
                ldebug("lost[{}][{}][{}] = {} + {}\n", u, j, k, lost[u][j - 1][k], lost[son[u][j - 1]][j - 1][k]);
            }
        }
        array<i64, 2> seq{{1LL, len[u]}}, ns;
        while (u > 1) {
            ldebug("u = {}\n", u);
            RFOR(j, LOG_N - 1, 0) {
                if (son[u][j] == -1) continue;
                ns[0] = seq[0] + lost[u][j][0];
                ns[1] = seq[1] - lost[u][j][1];
                ldebug("u = {}, j = {}, ns = [{}, {}]\n", u, j, ns[0], ns[1]);
                if (ns[0] <= x[i] && x[i] <= ns[1]) {
                    ldebug("accept ns, now u = {}\n", son[u][j]);
                    seq = ns;
                    u = son[u][j];
                }
            }
            if (u > 1) {
                // 一定要跳一个轻儿子
                if (hs[u]) {
                    seq[hs[u]] -= len[ch[u][hs[u]]];
                } else {
                    seq[hs[u]] += len[ch[u][hs[u]]];
                }
                u = ch[u][!hs[u]];
                ldebug("jump light son, seq = [{}, {}], u = {}\n", seq[0], seq[1], u);
            }
        }
        cout << u << '\n';
    }
}
int main() {
    fast_io();
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
#ifdef DEBUG
        cerr << endl;
#endif
    }
    return 0;
}

提出情報

提出日時
問題 G - Binary Cat
ユーザ lrx___
言語 C++ 20 (gcc 12.2)
得点 0
コード長 3583 Byte
結果 WA
実行時間 5865 ms
メモリ 211120 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 625
結果
AC × 1
AC × 37
WA × 19
セット名 テストケース
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random2_00.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random2_10.txt, random2_11.txt, random2_12.txt, random2_13.txt, random2_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3432 KiB
hand_00.txt WA 3666 ms 211000 KiB
hand_01.txt AC 3225 ms 211120 KiB
hand_02.txt WA 3657 ms 211052 KiB
hand_03.txt AC 2418 ms 210984 KiB
hand_04.txt AC 1444 ms 211024 KiB
hand_05.txt WA 5865 ms 211044 KiB
hand_06.txt AC 369 ms 210920 KiB
hand_07.txt AC 4720 ms 210924 KiB
hand_08.txt AC 160 ms 210928 KiB
hand_09.txt AC 1 ms 3476 KiB
random2_00.txt AC 375 ms 196844 KiB
random2_01.txt AC 1290 ms 194712 KiB
random2_02.txt AC 1377 ms 209820 KiB
random2_03.txt AC 348 ms 201428 KiB
random2_04.txt AC 1199 ms 200612 KiB
random2_05.txt AC 1216 ms 199284 KiB
random2_06.txt AC 394 ms 198792 KiB
random2_07.txt AC 1438 ms 209172 KiB
random2_08.txt AC 1344 ms 196692 KiB
random2_09.txt WA 393 ms 196904 KiB
random2_10.txt WA 1121 ms 203012 KiB
random2_11.txt WA 1076 ms 198760 KiB
random2_12.txt WA 343 ms 199496 KiB
random2_13.txt WA 991 ms 198844 KiB
random2_14.txt WA 1031 ms 202812 KiB
random_00.txt AC 481 ms 210936 KiB
random_01.txt WA 595 ms 210916 KiB
random_02.txt AC 822 ms 210944 KiB
random_03.txt AC 833 ms 210944 KiB
random_04.txt WA 677 ms 210948 KiB
random_05.txt AC 476 ms 210996 KiB
random_06.txt AC 731 ms 211036 KiB
random_07.txt WA 706 ms 211064 KiB
random_08.txt AC 833 ms 211016 KiB
random_09.txt AC 830 ms 210852 KiB
random_10.txt WA 590 ms 210980 KiB
random_11.txt AC 831 ms 210920 KiB
random_12.txt AC 814 ms 210960 KiB
random_13.txt WA 612 ms 210832 KiB
random_14.txt AC 823 ms 210876 KiB
random_15.txt AC 485 ms 210920 KiB
random_16.txt WA 592 ms 210988 KiB
random_17.txt AC 825 ms 210880 KiB
random_18.txt AC 842 ms 210948 KiB
random_19.txt WA 713 ms 211000 KiB
random_20.txt AC 492 ms 211120 KiB
random_21.txt AC 841 ms 210912 KiB
random_22.txt WA 656 ms 211012 KiB
random_23.txt AC 723 ms 210932 KiB
random_24.txt AC 695 ms 210860 KiB
random_25.txt WA 563 ms 210980 KiB
random_26.txt AC 693 ms 210916 KiB
random_27.txt AC 707 ms 210956 KiB
random_28.txt WA 559 ms 210800 KiB
random_29.txt AC 728 ms 210976 KiB