結果
問題 | No.2325 Skill Tree |
ユーザー |
![]() |
提出日時 | 2023-05-28 14:05:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 665 ms / 3,000 ms |
コード長 | 1,423 bytes |
コンパイル時間 | 3,866 ms |
コンパイル使用メモリ | 261,624 KB |
最終ジャッジ日時 | 2025-02-13 10:48:30 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; // importbisect template <typename T> int bisect_left(vector<T> &X, T v){ return lower_bound(X.begin(), X.end(), v) - X.begin(); } template <typename T> int bisect_right(vector<T> &X, T v){ return upper_bound(X.begin(), X.end(), v) - X.begin(); } // ----- int main(){ int n; cin >> n; vector<ll> l(n); vector<int> a(n); vector<vector<int>> ikeru(n, vector<int>(0)); for (int i=0; i<n-1; i++){ cin >> l[i+1] >> a[i+1]; ikeru[a[i+1]-1].push_back(i+1); } priority_queue<pair<ll,int>> pq; vector<ll> can(n, 2e9); can[0] = 1; for (int j:ikeru[0]){ pq.push(pair(-l[j], j)); } // heiro ha kangaenakute yoi. ll f = 1; vector<bool> tansaku(n); tansaku[0] = true; while(!pq.empty()){ ll lv = -pq.top().first; int ind = pq.top().second; pq.pop(); if (tansaku[ind]) continue; tansaku[ind] = true; can[ind] = max(f, lv); f = max(f, lv); for (int j: ikeru[ind]){ if (!tansaku[j]) pq.push(pair(-l[j], j)); } } vector<ll> ls = can; sort(ls.begin(), ls.end()); int q; cin >> q; for (int i=0; i<q; i++){ int t; cin >> t; if (t == 1){ int x; cin >> x; cout << bisect_right(ls, (ll)x) << "\n"; }else{ int x; cin >> x; x--; if (can[x] > 15e8){ cout << -1 << "\n"; }else{ cout << can[x] << "\n"; } } } }