結果

問題 No.2325 Skill Tree
ユーザー kobaryo222kobaryo222
提出日時 2023-05-28 14:54:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,921 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 218,256 KB
実行使用メモリ 57,512 KB
最終ジャッジ日時 2023-08-27 10:53:36
合計ジャッジ時間 29,933 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 430 ms
29,700 KB
testcase_12 AC 889 ms
57,512 KB
testcase_13 AC 893 ms
57,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 877 ms
57,236 KB
testcase_17 AC 857 ms
57,240 KB
testcase_18 AC 849 ms
57,300 KB
testcase_19 AC 849 ms
57,408 KB
testcase_20 WA -
testcase_21 AC 833 ms
57,264 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 898 ms
57,248 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1LL << 60)
#define all(v) (v).begin(), (v).end()

template <class T>
void chmin(T &a, T b) {
    if (a > b) a = b;
}

template <class T>
void chmax(T &a, T b) {
    if (a < b) a = b;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> L(N), A(N);
    rep(i, N - 1) {
        cin >> L[i + 1] >> A[i + 1];
        A[i + 1]--;
    }
    ll Q;
    cin >> Q;
    vector<ll> l(N);
    rep(i, N) { l[i] = L[i]; }
    sort(all(l));
    l.erase(unique(all(l)), l.end());
    map<ll, ll> comp, rev;
    rep(i, l.size()) {
        comp[l[i]] = i;
        rev[i] = l[i];
    }
    rep(i, N) { L[i] = comp[L[i]]; }
    vector<vector<ll>> level_to_idx(l.size()), A_to_idx(N);
    rep(i, N) {
        level_to_idx[L[i]].push_back(i);
        A_to_idx[A[i]].push_back(i);
    }
    vector<ll> ans(l.size());
    vector<ll> ans2(N, -1);
    vector<ll> used(N);
    ll t = 1;
    ans[0] = 1;
    used[0] = 1;
    rep(i, l.size()) {
        if (i == 0) continue;
        rep(j, level_to_idx[i].size()) {
            ll idx = level_to_idx[i][j];
            if (used[idx] == 1) continue;
            if (used[A[idx]] == 0) continue;
            used[idx] = 1;
            ans2[idx] = rev[i];
            t++;
            rep(k, A_to_idx[A[i]].size()) {
                ll jdx = A_to_idx[A[i]][k];
                if (used[jdx]) continue;
                if (L[jdx] > i) continue;
                used[jdx] = 1;
                ans2[jdx] = rev[i];
                t++;
            }
        }
        ans[i] = t;
    }
    rep(i, Q) {
        ll t, x;
        cin >> t >> x;
        if (t == 1) {
            auto itr = upper_bound(all(l), x);
            --itr;
            cout << ans[distance(l.begin(), itr)] << endl;
        } else {
            x--;
            cout << ans2[x] << endl;
        }
    }
}
0