結果

問題 No.2643 Many Range Sums Problems
ユーザー noya2noya2
提出日時 2024-02-13 03:54:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 8,000 ms
コード長 1,280 bytes
コンパイル時間 2,850 ms
コンパイル使用メモリ 251,556 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-13 15:31:01
合計ジャッジ時間 7,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 161 ms
6,676 KB
testcase_04 AC 133 ms
6,676 KB
testcase_05 AC 128 ms
6,676 KB
testcase_06 AC 187 ms
6,676 KB
testcase_07 AC 187 ms
6,676 KB
testcase_08 AC 168 ms
6,676 KB
testcase_09 AC 184 ms
6,676 KB
testcase_10 AC 167 ms
6,676 KB
testcase_11 AC 126 ms
6,676 KB
testcase_12 AC 192 ms
6,676 KB
testcase_13 AC 225 ms
6,676 KB
testcase_14 AC 170 ms
6,676 KB
testcase_15 AC 176 ms
6,676 KB
testcase_16 AC 147 ms
6,676 KB
testcase_17 AC 161 ms
6,676 KB
testcase_18 AC 79 ms
6,676 KB
testcase_19 AC 11 ms
6,676 KB
testcase_20 AC 41 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 46 ms
6,676 KB
testcase_23 AC 79 ms
6,676 KB
testcase_24 AC 150 ms
6,676 KB
testcase_25 AC 136 ms
6,676 KB
testcase_26 AC 14 ms
6,676 KB
testcase_27 AC 16 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 187 ms
6,676 KB
testcase_31 AC 189 ms
6,676 KB
testcase_32 AC 190 ms
6,676 KB
testcase_33 AC 190 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll linf = 1e18;

template<typename T>
bool chmin(T &a, const T &b){
    if (a <= b) return false;
    a = b;
    return true;
}

template<typename T>
bool chmax(T &a, const T &b){
    if (a >= b) return false;
    a = b;
    return true;
}

int main(){
    int n; cin >> n;
    ll k; cin >> k;
    vector<int> rs(n);
    vector<ll> xs(n);
    for (int i = 0; i < n; i++){
        cin >> rs[i] >> xs[i];
    }
    for (int i = 0; i < n; i++){
        vector<ll> hs(n+1,0);
        vector<bool> root(n+1,false);
        root[n] = true;
        for (int j = n-1; j >= 0; j--){
            if (j == i) continue;
            root[j] = root[rs[j]];
            hs[j] = hs[rs[j]] + xs[j];
        }
        ll le = -linf, ri = linf;
        for (int j = 0; j < n; j++){
            ll a = hs[j] - hs[j+1];
            if (root[j] == root[j+1]){
                if (a < 0 || a > k){
                    le = linf+1;
                }
            }
            else if (root[j]){
                chmin(ri,a);
                chmax(le,a-k);
            }
            else {
                chmin(ri,k-a);
                chmax(le,-a);
            }
        }
        cout << (le <= ri ? "Yes" : "No") << '\n';
    }
}
0