結果
問題 | No.2325 Skill Tree |
ユーザー | Ajinoko33 |
提出日時 | 2023-05-28 15:03:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 580 ms / 3,000 ms |
コード長 | 1,905 bytes |
コンパイル時間 | 3,221 ms |
コンパイル使用メモリ | 211,764 KB |
実行使用メモリ | 19,556 KB |
最終ジャッジ日時 | 2023-08-27 11:19:11 |
合計ジャッジ時間 | 22,815 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 254 ms
5,100 KB |
testcase_08 | AC | 172 ms
9,700 KB |
testcase_09 | AC | 292 ms
7,532 KB |
testcase_10 | AC | 216 ms
14,404 KB |
testcase_11 | AC | 294 ms
10,956 KB |
testcase_12 | AC | 538 ms
19,348 KB |
testcase_13 | AC | 538 ms
19,408 KB |
testcase_14 | AC | 533 ms
19,268 KB |
testcase_15 | AC | 523 ms
19,256 KB |
testcase_16 | AC | 534 ms
19,556 KB |
testcase_17 | AC | 532 ms
19,352 KB |
testcase_18 | AC | 528 ms
19,404 KB |
testcase_19 | AC | 528 ms
19,268 KB |
testcase_20 | AC | 521 ms
19,328 KB |
testcase_21 | AC | 528 ms
19,272 KB |
testcase_22 | AC | 539 ms
19,272 KB |
testcase_23 | AC | 539 ms
19,404 KB |
testcase_24 | AC | 543 ms
19,332 KB |
testcase_25 | AC | 536 ms
19,216 KB |
testcase_26 | AC | 536 ms
19,256 KB |
testcase_27 | AC | 562 ms
19,132 KB |
testcase_28 | AC | 567 ms
18,960 KB |
testcase_29 | AC | 562 ms
19,076 KB |
testcase_30 | AC | 562 ms
18,956 KB |
testcase_31 | AC | 567 ms
19,060 KB |
testcase_32 | AC | 548 ms
19,004 KB |
testcase_33 | AC | 530 ms
18,956 KB |
testcase_34 | AC | 554 ms
19,008 KB |
testcase_35 | AC | 580 ms
19,016 KB |
testcase_36 | AC | 558 ms
19,004 KB |
testcase_37 | AC | 570 ms
19,000 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) #define Sort(vector) sort(vector.begin(), vector.end()) #define Reverse(vector) reverse(vector.begin(), vector.end()) #define RSort(vector) sort(vector.rbegin(), vector.rend()) using ll = long long; using P = pair<ll,ll>; using TU = tuple<int,int,int>; using vint = vector<int>; using vvint = vector<vint>; using vvvint = vector<vvint>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; template<typename T> istream &operator>>(istream &is,vector<T> &v){for(T &in:v){is>>in;}return is;} template<typename T> ostream &operator<<(ostream &os,vector<T> &v){for(int i=0;i<(int)v.size();i++){os<<v[i]<<" \n"[i==(int)v.size()-1];}return os;} template<typename T> istream &operator>>(istream &is,vector<vector<T>> &v){for(vector<T> &in:v){is>>in;}return is;} template<typename T> ostream &operator<<(ostream &os,vector<vector<T>> &v){for(vector<T> &out:v){os<<out;}return os;} int main(){ int n;cin>>n; vector<P> waza(n+1); for(int i=2;i<=n;i++){ ll l,a;cin>>l>>a; waza[i]={l,a}; } waza[1]={0,0}; // waza[0]={0,-1}; vector<vector<P>> nxtWaza(n+1); for(int i=2;i<=n;i++){ auto [l,a]=waza[i]; nxtWaza[a].push_back({l,i}); } const ll INF=1e15; vll lowerLv(n+1,INF); // lowerLv[i]:=技iを覚えるのに必要な最小レベル lowerLv[0]=-1; auto dfs=[&](auto f,int now,ll lv)->void{ // 技nowを覚える lowerLv[now]=lv; for(auto [l,nxt]:nxtWaza[now]){ f(f,nxt,max(lv,l)); } }; dfs(dfs,1,0); vll cp=lowerLv; cp[0]=INF; Sort(cp); int q;cin>>q; rep(_,q) { ll c,x;cin>>c>>x; if(c==1){ int res=upper_bound(cp.begin(),cp.end(),x)-cp.begin(); // res--; cout<< res <<'\n'; }else{ if(lowerLv[x]!=INF) cout<< lowerLv[x] <<'\n'; else cout<< -1 <<'\n'; } } return 0; }