結果

問題 No.2643 Many Range Sums Problems
ユーザー てんぷらてんぷら
提出日時 2024-02-19 23:18:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,057 ms / 8,000 ms
コード長 2,080 bytes
コンパイル時間 4,387 ms
コンパイル使用メモリ 308,264 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 23:19:10
合計ジャッジ時間 13,334 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 189 ms
6,676 KB
testcase_04 AC 140 ms
6,676 KB
testcase_05 AC 83 ms
6,676 KB
testcase_06 AC 238 ms
6,676 KB
testcase_07 AC 230 ms
6,676 KB
testcase_08 AC 204 ms
6,676 KB
testcase_09 AC 236 ms
6,676 KB
testcase_10 AC 198 ms
6,676 KB
testcase_11 AC 80 ms
6,676 KB
testcase_12 AC 1,057 ms
6,676 KB
testcase_13 AC 301 ms
6,676 KB
testcase_14 AC 209 ms
6,676 KB
testcase_15 AC 212 ms
6,676 KB
testcase_16 AC 161 ms
6,676 KB
testcase_17 AC 188 ms
6,676 KB
testcase_18 AC 67 ms
6,676 KB
testcase_19 AC 9 ms
6,676 KB
testcase_20 AC 31 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 131 ms
6,676 KB
testcase_23 AC 255 ms
6,676 KB
testcase_24 AC 479 ms
6,676 KB
testcase_25 AC 473 ms
6,676 KB
testcase_26 AC 38 ms
6,676 KB
testcase_27 AC 42 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 228 ms
6,676 KB
testcase_31 AC 236 ms
6,676 KB
testcase_32 AC 1,048 ms
6,676 KB
testcase_33 AC 1,042 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

ll floor(ll x, ll m) {
    ll r = (x % m + m) % m;
    return (x - r) / m;
}

ll ceil(ll x, ll m) {
    ll r = (x % m + m) % m;
    return (x - r) / m + (r > 0);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> r(n);
    vector<ll> a(n);
    rep(i, n) cin >> r[i] >> a[i];
    rep(i, n) {
        vector<ll> coef(n), ret(n), sc(n + 1), sr(n + 1);
        bool ok = true;
        for(int j = n - 1; j >= 0; j--) {
            sc[j] += sc[j + 1];
            sr[j] += sr[j + 1];
            if(j == i) {
                coef[j] = 1;
                sc[j] += 1;
                continue;
            }
            ll rsum = sr[j] - sr[r[j]];
            ll csum = sc[j] - sc[r[j]];
            coef[j] = -csum;
            ret[j] = -rsum + a[j];
            sc[j] += coef[j];
            sr[j] += ret[j];
        }
        // rep(i, n) cout << coef[i] << " ";
        // cout << endl;
        // rep(i, n) cout << ret[i] << " ";
        // cout << endl;
        ll mi = 0, ma = k;
        rep(j, n) {
            if(coef[j] == 0) {
                if(ret[j] < 0 || ret[j] > k) {
                    ok = false;
                }
            }
            if(coef[j] < 0) {
                mi = max(mi, ceil(ret[j] - k, abs(coef[j])));
                ma = min(ma, floor(ret[j], abs(coef[j])));
            }
            if(coef[j] > 0) {
                mi = max(mi, ceil(-ret[j], abs(coef[j])));
                ma = min(ma, floor(-ret[j] + k, abs(coef[j])));
            }
        }
        // cout << mi << " " << ma << endl;
        if(mi > ma) {
            ok = false;
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}
0