結果

問題 No.2325 Skill Tree
ユーザー KKT89KKT89
提出日時 2023-05-28 14:37:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 3,000 ms
コード長 1,384 bytes
コンパイル時間 2,795 ms
コンパイル使用メモリ 222,056 KB
実行使用メモリ 13,524 KB
最終ジャッジ日時 2023-08-27 10:14:57
合計ジャッジ時間 10,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 40 ms
4,572 KB
testcase_08 AC 46 ms
7,016 KB
testcase_09 AC 53 ms
5,604 KB
testcase_10 AC 68 ms
10,120 KB
testcase_11 AC 66 ms
7,736 KB
testcase_12 AC 133 ms
12,696 KB
testcase_13 AC 132 ms
13,016 KB
testcase_14 AC 132 ms
12,776 KB
testcase_15 AC 132 ms
12,736 KB
testcase_16 AC 132 ms
12,792 KB
testcase_17 AC 128 ms
12,700 KB
testcase_18 AC 129 ms
12,824 KB
testcase_19 AC 129 ms
12,664 KB
testcase_20 AC 126 ms
12,736 KB
testcase_21 AC 126 ms
13,008 KB
testcase_22 AC 131 ms
12,916 KB
testcase_23 AC 131 ms
12,684 KB
testcase_24 AC 131 ms
12,664 KB
testcase_25 AC 129 ms
12,668 KB
testcase_26 AC 130 ms
12,752 KB
testcase_27 AC 161 ms
13,332 KB
testcase_28 AC 163 ms
13,304 KB
testcase_29 AC 162 ms
13,244 KB
testcase_30 AC 160 ms
13,268 KB
testcase_31 AC 160 ms
13,252 KB
testcase_32 AC 146 ms
13,440 KB
testcase_33 AC 150 ms
13,244 KB
testcase_34 AC 148 ms
13,340 KB
testcase_35 AC 162 ms
13,380 KB
testcase_36 AC 157 ms
13,524 KB
testcase_37 AC 163 ms
13,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ok(n,-1);
    ok[0] = 0;
    vector<vector<pair<int,int>>> g(n);
    for (int i = 1; i < n; ++i) {
        int l,a; cin >> l >> a;
        a--;
        g[a].push_back({i,l});
    }
    {
        queue<int> q;
        q.push(0);
        while (q.size()) {
            int s = q.front(); q.pop();
            for (auto p : g[s]) {
                ok[p.first] = max(p.second, ok[s]);
                q.push(p.first);
            }
        }
    }
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        if (ok[i] != -1) {
            v.push_back(ok[i]);
        }
    }
    sort(v.begin(), v.end());
    int q; cin >> q;
    while (q--) {
        int t,x; cin >> t >> x;
        if (t == 1) {
            cout << lower_bound(v.begin(), v.end(), x+1) - v.begin() << "\n";
        }
        else {
            cout << ok[x-1] << "\n";
        }
    }
}
0