結果

問題 No.2643 Many Range Sums Problems
ユーザー てんぷらてんぷら
提出日時 2024-02-19 23:07:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,078 bytes
コンパイル時間 5,319 ms
コンパイル使用メモリ 308,648 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 23:07:49
合計ジャッジ時間 13,565 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 283 ms
6,676 KB
testcase_07 AC 275 ms
6,676 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 232 ms
6,676 KB
testcase_11 AC 100 ms
6,676 KB
testcase_12 AC 753 ms
6,676 KB
testcase_13 AC 348 ms
6,676 KB
testcase_14 WA -
testcase_15 AC 248 ms
6,676 KB
testcase_16 AC 191 ms
6,676 KB
testcase_17 WA -
testcase_18 AC 77 ms
6,676 KB
testcase_19 AC 11 ms
6,676 KB
testcase_20 AC 36 ms
6,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 276 ms
6,676 KB
testcase_31 WA -
testcase_32 AC 737 ms
6,676 KB
testcase_33 AC 766 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], abs(coef[j])) - k);
                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], abs(coef[j])) + k);
            }
        }
        // cout << mi << " " << ma << endl;
        if(mi > ma) {
            ok = false;
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}
0