結果

問題 No.2325 Skill Tree
ユーザー HaaHaa
提出日時 2023-05-28 14:10:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 602 ms / 3,000 ms
コード長 1,053 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 174,760 KB
実行使用メモリ 18,412 KB
最終ジャッジ日時 2023-08-27 09:09:56
合計ジャッジ時間 22,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 260 ms
5,108 KB
testcase_08 AC 177 ms
9,416 KB
testcase_09 AC 296 ms
7,280 KB
testcase_10 AC 228 ms
13,516 KB
testcase_11 AC 302 ms
10,548 KB
testcase_12 AC 556 ms
18,400 KB
testcase_13 AC 553 ms
18,272 KB
testcase_14 AC 553 ms
18,332 KB
testcase_15 AC 555 ms
18,244 KB
testcase_16 AC 550 ms
18,264 KB
testcase_17 AC 551 ms
18,320 KB
testcase_18 AC 543 ms
18,412 KB
testcase_19 AC 544 ms
18,176 KB
testcase_20 AC 540 ms
18,332 KB
testcase_21 AC 540 ms
18,280 KB
testcase_22 AC 555 ms
18,220 KB
testcase_23 AC 552 ms
18,324 KB
testcase_24 AC 554 ms
18,244 KB
testcase_25 AC 551 ms
18,180 KB
testcase_26 AC 558 ms
18,260 KB
testcase_27 AC 597 ms
17,452 KB
testcase_28 AC 598 ms
17,772 KB
testcase_29 AC 593 ms
17,648 KB
testcase_30 AC 590 ms
17,692 KB
testcase_31 AC 602 ms
17,800 KB
testcase_32 AC 573 ms
17,876 KB
testcase_33 AC 574 ms
17,476 KB
testcase_34 AC 572 ms
17,696 KB
testcase_35 AC 596 ms
17,804 KB
testcase_36 AC 597 ms
17,804 KB
testcase_37 AC 599 ms
17,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VVI g(n);
    VI l(n), a(n);
    REP(i,n-1){
        cin >> l[i+1] >> a[i+1], a[i+1]--;
        g[a[i+1]].push_back(i+1);
    }
    VI ls(n,INF), mls(n,-1);
    function<void(int,int)> dfs=[&](int v, int m){
        ls[v]=m;
        mls[v]=m;
        for(auto to:g[v]){
            dfs(to,max(m,(int)l[to]));
        }
    };
    dfs(0,0);
    sort(ALL(ls));
    int q; cin >> q;
    int t, x;
    REP(i,q){
        cin >> t >> x;
        if(t==1)
            cout << upper_bound(ALL(ls),x)-ls.begin() << endl;
        else
            cout << mls[x-1] << endl;
    }
    return 0;
}
0