結果

問題 No.2325 Skill Tree
ユーザー akasinnakasinn
提出日時 2023-05-28 15:45:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 561 ms / 3,000 ms
コード長 2,104 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 175,788 KB
実行使用メモリ 6,716 KB
最終ジャッジ日時 2023-08-27 12:53:03
合計ジャッジ時間 20,188 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 258 ms
4,380 KB
testcase_08 AC 161 ms
4,380 KB
testcase_09 AC 288 ms
4,376 KB
testcase_10 AC 195 ms
4,920 KB
testcase_11 AC 283 ms
4,380 KB
testcase_12 AC 502 ms
5,548 KB
testcase_13 AC 506 ms
5,756 KB
testcase_14 AC 507 ms
5,680 KB
testcase_15 AC 506 ms
5,544 KB
testcase_16 AC 502 ms
5,596 KB
testcase_17 AC 491 ms
5,556 KB
testcase_18 AC 502 ms
5,548 KB
testcase_19 AC 490 ms
5,544 KB
testcase_20 AC 495 ms
5,640 KB
testcase_21 AC 490 ms
5,536 KB
testcase_22 AC 520 ms
5,580 KB
testcase_23 AC 509 ms
5,540 KB
testcase_24 AC 507 ms
5,600 KB
testcase_25 AC 507 ms
5,676 KB
testcase_26 AC 507 ms
5,724 KB
testcase_27 AC 553 ms
6,372 KB
testcase_28 AC 551 ms
6,716 KB
testcase_29 AC 541 ms
6,336 KB
testcase_30 AC 548 ms
6,284 KB
testcase_31 AC 549 ms
6,376 KB
testcase_32 AC 504 ms
6,268 KB
testcase_33 AC 512 ms
6,388 KB
testcase_34 AC 516 ms
6,436 KB
testcase_35 AC 551 ms
6,208 KB
testcase_36 AC 545 ms
5,904 KB
testcase_37 AC 561 ms
6,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//MMA Contest 015 C
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;

vector<int> L={0};
vector<int> A={-1};
vector<int> ReallyDemandedLevel;
//-3:計算途中、-2:未計算、-1:不可能、非負整数:スライムがその技を覚えるために必要なレベルの最小値


int f_ReallyDemandedLevel(int n){
  if(ReallyDemandedLevel.at(n)==-3)return -1;//閉路
  ReallyDemandedLevel.at(n)=-3;
  int previous_node=A.at(n);
  int &a=ReallyDemandedLevel.at(previous_node);
  if(a==-2)a=f_ReallyDemandedLevel(previous_node);
  if(a==-1 || a==-3)return -1;
  int b=L.at(n);
  return max(a,b);
}

//main関数ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 
int main(){
  int n; cin>>n;
  for(int i=1;i<n;i++){
    int l,a; cin>>l>>a;
    L.push_back(l);
    A.push_back(a-1);
  }
  ReallyDemandedLevel.assign(n,-2);
  ReallyDemandedLevel.at(0)=0;
  for(int i=1;i<n;i++){
    if(ReallyDemandedLevel.at(i)==-2){
      ReallyDemandedLevel.at(i)=f_ReallyDemandedLevel(i);
    }
  }
  
  //for(int i=0;i<n;i++){
   // cout<<i<<' '<<ReallyDemandedLevel.at(i)<<endl;
  //}
  
  map<int,int>Mp;
  for(int l:ReallyDemandedLevel)if(l>=0)Mp[l]++;
  
  int sum=0;//クエリ1のためにMpを積分
  for(pair<int,int> p:Mp){
    sum+=p.second;
    Mp[p.first]=sum;
  }
  //for(pair<int,int> p:Mp)cout<<"Mp "<<p.first<<" "<<p.second<<endl;
  
  
  
  
  int q; cin>>q;
  //cout<<"q="<<q<<endl;
  while(q--){
    int query_type; cin>>query_type;
    if(query_type==1){//レベル x のスライムが覚えられる技の種類数の最大値を出力する。
      int x; cin>>x;
      auto itr=Mp.upper_bound(x);
      itr--;
      pair<int,int> p=*itr;
      cout<<p.second<<endl;
    }else{//スライムが技 y を覚えるために必要なレベルの最小値を出力する。技 y を覚えることができない場合には−1を出力する。
      int y; cin>>y;
      cout<<ReallyDemandedLevel.at(y-1)<<endl;
    }
  }
  return 0;
}
0