結果

問題 No.2325 Skill Tree
ユーザー shin3110shin3110
提出日時 2023-05-28 15:07:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,672 bytes
コンパイル時間 2,448 ms
コンパイル使用メモリ 182,988 KB
実行使用メモリ 20,148 KB
最終ジャッジ日時 2024-06-08 07:04:08
合計ジャッジ時間 20,714 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 148 ms
11,108 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 261 ms
11,392 KB
testcase_12 AC 500 ms
19,168 KB
testcase_13 AC 518 ms
19,172 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 500 ms
19,296 KB
testcase_17 AC 571 ms
19,200 KB
testcase_18 AC 558 ms
19,200 KB
testcase_19 AC 559 ms
19,200 KB
testcase_20 WA -
testcase_21 AC 548 ms
19,172 KB
testcase_22 AC 451 ms
19,200 KB
testcase_23 WA -
testcase_24 AC 449 ms
19,172 KB
testcase_25 AC 447 ms
19,164 KB
testcase_26 AC 455 ms
19,168 KB
testcase_27 AC 606 ms
20,140 KB
testcase_28 AC 616 ms
20,048 KB
testcase_29 AC 593 ms
20,144 KB
testcase_30 AC 596 ms
20,140 KB
testcase_31 AC 581 ms
20,012 KB
testcase_32 AC 631 ms
20,148 KB
testcase_33 AC 630 ms
20,016 KB
testcase_34 AC 629 ms
20,020 KB
testcase_35 AC 521 ms
20,016 KB
testcase_36 AC 517 ms
20,144 KB
testcase_37 AC 555 ms
20,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

              ∧∧∩ 
             ( ゚∀゚)/ キタ━━━━━━(゚∀゚)━━━━━━!!!!
            ⊂   ノ  ゆっくり見てってね!!!!!!!!
             (つ ノ
    o          (ノ
     \      ☆
             |      o
          (⌒ ⌒ヽ   /     ☆
    \  (´⌒  ⌒  ⌒ヾ   /
      ('⌒ ; ⌒   ::⌒  )
     (´     )     ::: ) /
  ☆─ (´⌒;:    ::⌒`) :;  )

*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define _GLIBCXX_DEBUG


ll l[200009], a[200009];
bool f[200009];

ll gcd(int i, map<ll, ll>& was, vector<int>& pnt) {
    f[i] = true;
    int w = l[i];
    int num;
    if(!f[a[i]]) {
        num = gcd(a[i], was, pnt);
    } else {
        num = was[a[i]];
    }
    if(num == -1) {
        return -1;
    }
    w = max(w, num);
    pnt.push_back(w);
    return w;
}


int countElementsLessThanOrEqual(const std::vector<int>& nums, int a) {
    int left = 0;
    int right = nums.size() - 1;

    // 二分探索
    while (left <= right) {
        int mid = left + (right - left) / 2;

        if (nums[mid] <= a) {
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }

    // leftはa以下の要素の個数を表す
    return left;
}








int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    rep(i, 2, n+1) {
        cin >> l[i] >> a[i];
    }
    map<ll, ll> was;
    rep(i, 1, n+1) {
        was[i] = -1;
    }
    vector<int> pnt;
    f[1] = true;
    was[1] = 0;
    pnt.push_back(0);
    rep(i, 2, n+1) {
        if(f[i]) continue;
        f[i] = true;
        ll num;
        if(!f[a[i]]) {
            num = gcd(a[i], was, pnt);
        } else {
            num = was[a[i]];
        }
        if(num == -1) {
            was[i] = -1;
            continue;
        }
        was[i] = max(l[i], num);
        pnt.push_back(was[i]);
    }
    sort(pnt.begin(), pnt.end());
    int q; cin >> q;
    while(q--) {
        int z; cin >> z;
        if(z == 1) {
            int x; cin >> x;
            int cnt = countElementsLessThanOrEqual(pnt, x);
            cout << cnt << endl;
        } else {
            int y; cin >> y;
            cout << was[y] << endl;
        }
    }
}
0