結果

問題 No.2325 Skill Tree
ユーザー bluebery1001bluebery1001
提出日時 2023-05-28 15:34:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,900 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 177,316 KB
実行使用メモリ 17,740 KB
最終ジャッジ日時 2023-08-27 12:27:42
合計ジャッジ時間 16,472 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,512 KB
testcase_01 AC 3 ms
4,500 KB
testcase_02 WA -
testcase_03 AC 3 ms
4,616 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 104 ms
6,028 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 203 ms
6,196 KB
testcase_12 AC 353 ms
7,848 KB
testcase_13 AC 343 ms
7,732 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 348 ms
7,992 KB
testcase_17 AC 347 ms
7,740 KB
testcase_18 AC 355 ms
7,808 KB
testcase_19 AC 348 ms
7,784 KB
testcase_20 WA -
testcase_21 AC 360 ms
7,712 KB
testcase_22 AC 343 ms
8,044 KB
testcase_23 WA -
testcase_24 AC 342 ms
7,736 KB
testcase_25 AC 341 ms
7,876 KB
testcase_26 AC 337 ms
7,740 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 #

using namespace std;
#include<bits/stdc++.h>
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15);_main(); return 0;}
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class ll> inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; }
template<class ll> inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i, star,fini) for (int i = star; i < fini; i++)
#define ALL(x) std::begin(x), std::end(x)
#define INF ((1LL<<62)-(1LL<<31))
#define bit(x,i)(((x)>>(i))&1)
long double distance(long double xi,long double yi,long double xj,long double yj){return sqrt(1.0*((xi-xj)*(xi-xj))+1.0*((yi-yj)*(yi-yj)));}
vector<ll>needlv(200005,-1);
ll l[200005],a[200005];
void kakutei(ll pos){
    if(needlv[pos]==-2)return;
    if(needlv[pos]!=-1)return;
    if(needlv[a[pos]]>-1){
        needlv[pos]=max(l[pos],l[a[pos]]);
    }
    else{
        needlv[pos]=-2;
        kakutei(a[pos]);
    }
}
void _main(){
    ll n;cin >> n;
    l[0]=0;a[0]=0;needlv[0]=0;
    rep(i,1,n){
        cin >> l[i] >> a[i];
        a[i]--;
    }
    rep(i,0,n){
        kakutei(i);
    }
    map<ll,ll>qone;
    for(ll i:needlv){
        if(i<0)continue;
        qone[i]++;
        
    }
    vector<ll>ans;
    vector<ll>ans_name;
    ll prev = 0;
    for(auto i:qone){
        ans_name.push_back(i.first);
        ans.push_back(prev+i.second);
        prev = ans.back();
    }
    
    ll q;cin >> q;
    while (q--)
    {
        ll t,x;cin >> t;
        if(t==1){
            cin >> x;
            ll pos = upper_bound(ALL(ans_name),x)-ans_name.begin();
            pos--;
            cout<<ans[pos]<<endl;
        }
        else{
            cin >> x;
            cout<<(needlv[x-1]>0?needlv[x-1]:-1)<<endl;
        }
    }
    
}
0