結果

問題 No.2325 Skill Tree
ユーザー どりみあんどりみあん
提出日時 2023-05-28 15:42:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 589 ms / 3,000 ms
コード長 2,550 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 213,240 KB
実行使用メモリ 14,600 KB
最終ジャッジ日時 2023-08-27 12:46:51
合計ジャッジ時間 21,857 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 260 ms
4,764 KB
testcase_08 AC 170 ms
7,624 KB
testcase_09 AC 293 ms
6,180 KB
testcase_10 AC 215 ms
10,676 KB
testcase_11 AC 294 ms
8,340 KB
testcase_12 AC 536 ms
14,288 KB
testcase_13 AC 530 ms
14,272 KB
testcase_14 AC 536 ms
14,028 KB
testcase_15 AC 539 ms
14,092 KB
testcase_16 AC 534 ms
14,204 KB
testcase_17 AC 520 ms
13,996 KB
testcase_18 AC 528 ms
14,128 KB
testcase_19 AC 527 ms
14,156 KB
testcase_20 AC 528 ms
13,972 KB
testcase_21 AC 525 ms
14,032 KB
testcase_22 AC 537 ms
14,200 KB
testcase_23 AC 537 ms
14,040 KB
testcase_24 AC 539 ms
14,008 KB
testcase_25 AC 534 ms
14,080 KB
testcase_26 AC 538 ms
14,008 KB
testcase_27 AC 576 ms
14,336 KB
testcase_28 AC 573 ms
14,556 KB
testcase_29 AC 576 ms
14,332 KB
testcase_30 AC 573 ms
14,600 KB
testcase_31 AC 574 ms
14,596 KB
testcase_32 AC 555 ms
14,420 KB
testcase_33 AC 556 ms
14,204 KB
testcase_34 AC 553 ms
14,300 KB
testcase_35 AC 589 ms
14,348 KB
testcase_36 AC 577 ms
14,540 KB
testcase_37 AC 585 ms
14,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1000000000000000000;
const int INF=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){T c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    int N;
    cin>>N;
    vi vertex(N+1,-1);
    vector<pair<int,int>> skills(N+1);
    vii graph(N+1);
    REP(i,2,N+1){
        int l,a;
        cin>>l>>a;
        skills[i]={l,a};
    }


    REP(i,2,N+1){
        graph[skills[i].second].pb(i);
    }
    
    queue<pair<int,int>>que;
    que.push({1,1});

    while(!que.empty()){
        auto [x,level]=que.front();
        que.pop();

        for(auto y:graph[x]){
            if(vertex[y]!=-1)continue;
            vertex[y]=max(level,skills[y].first);
            que.push({y,vertex[y]});
        }
    }

    vi sortedSkills;
    sortedSkills.pb(1);
    rep(i,N+1){
        if(vertex[i]>0)sortedSkills.pb(vertex[i]);
    }
    sort(ALL(sortedSkills));

    int Q;
    cin>>Q;
    rep(q,Q){
        int p;
        cin>>p;
        if(p==1){
            int x;
            cin>>x;
            cout<<upper_bound(ALL(sortedSkills),x)-sortedSkills.begin()<<endl;
        }else{
            int y;
            cin>>y;
            cout<<vertex[y]<<endl;
        }
    }
    return 0;
}
/*
クエリ系は前処理がいる。
累積和かなあ
二分探索が使えそう
sortして、要求レベルが低い技ごとに考えていく?<-だめ
levelに書く技の要求レベルを持たせる。
技の習得を待つ必要があるときはどうしたら良いんだ
技を深掘りしていく。その技自体を覚えるレベルと、必要な技のレベルから決めていく?
通っていったところをqueで管理して、レベルを反映させてく?

力技でいける?
*/
0