結果

問題 No.2325 Skill Tree
ユーザー shobonvipshobonvip
提出日時 2023-05-28 14:05:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 641 ms / 3,000 ms
コード長 1,423 bytes
コンパイル時間 4,404 ms
コンパイル使用メモリ 269,224 KB
実行使用メモリ 17,388 KB
最終ジャッジ日時 2023-08-27 09:01:53
合計ジャッジ時間 24,896 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 261 ms
5,040 KB
testcase_08 AC 178 ms
8,840 KB
testcase_09 AC 293 ms
7,140 KB
testcase_10 AC 227 ms
13,140 KB
testcase_11 AC 305 ms
10,000 KB
testcase_12 AC 557 ms
17,380 KB
testcase_13 AC 553 ms
17,384 KB
testcase_14 AC 556 ms
17,248 KB
testcase_15 AC 560 ms
17,260 KB
testcase_16 AC 558 ms
17,308 KB
testcase_17 AC 548 ms
17,236 KB
testcase_18 AC 545 ms
17,280 KB
testcase_19 AC 546 ms
17,352 KB
testcase_20 AC 552 ms
17,312 KB
testcase_21 AC 551 ms
17,248 KB
testcase_22 AC 559 ms
17,312 KB
testcase_23 AC 556 ms
17,336 KB
testcase_24 AC 553 ms
17,156 KB
testcase_25 AC 556 ms
17,388 KB
testcase_26 AC 553 ms
17,304 KB
testcase_27 AC 639 ms
16,776 KB
testcase_28 AC 640 ms
16,864 KB
testcase_29 AC 632 ms
16,552 KB
testcase_30 AC 638 ms
16,504 KB
testcase_31 AC 641 ms
16,572 KB
testcase_32 AC 610 ms
16,452 KB
testcase_33 AC 613 ms
16,816 KB
testcase_34 AC 613 ms
16,764 KB
testcase_35 AC 636 ms
16,516 KB
testcase_36 AC 635 ms
16,496 KB
testcase_37 AC 640 ms
16,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
			}
		}
	}
}
0