結果

問題 No.2325 Skill Tree
ユーザー kobaryo222kobaryo222
提出日時 2023-05-28 14:44:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,304 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 215,360 KB
実行使用メモリ 48,780 KB
最終ジャッジ日時 2023-08-27 10:32:14
合計ジャッジ時間 32,526 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 297 ms
9,044 KB
testcase_08 AC 307 ms
21,856 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 468 ms
25,440 KB
testcase_12 AC 988 ms
48,472 KB
testcase_13 AC 980 ms
48,524 KB
testcase_14 AC 1,001 ms
48,456 KB
testcase_15 WA -
testcase_16 AC 977 ms
48,408 KB
testcase_17 AC 916 ms
48,456 KB
testcase_18 AC 965 ms
48,732 KB
testcase_19 AC 986 ms
48,468 KB
testcase_20 WA -
testcase_21 AC 928 ms
48,408 KB
testcase_22 AC 989 ms
48,408 KB
testcase_23 WA -
testcase_24 AC 963 ms
48,584 KB
testcase_25 AC 979 ms
48,532 KB
testcase_26 AC 987 ms
48,412 KB
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;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^-1
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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, vector<ll>> mpl, mpa;
    rep(i, N - 1) {
        mpl[L[i + 1]].push_back(i + 1);
        mpa[A[i + 1]].push_back(i + 1);
    }
    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, mpl[l[i]].size()) {
            ll idx = mpl[l[i]][j];
            if (used[idx] == 1) continue;
            if (used[A[idx]] == 0) continue;
            used[idx] = 1;
            ans2[idx] = l[i];
            t++;
            rep(k, mpa[idx].size()) {
                ll jdx = mpa[idx][k];
                if (used[jdx]) continue;
                if (L[jdx] > l[i]) continue;
                used[jdx] = 1;
                ans2[jdx] = l[i];
                t++;
            }
        }
        ans[i] = t;
    }
    // cout << endl;
    // rep(i, l.size()) { cout << l[i] << " " << ans[i] << endl; }
    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