結果
問題 | No.2643 Many Range Sums Problems |
ユーザー | SSRS |
提出日時 | 2024-02-19 23:24:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,042 bytes |
コンパイル時間 | 2,787 ms |
コンパイル使用メモリ | 220,292 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-29 03:07:15 |
合計ジャッジ時間 | 3,909 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 13 ms
6,816 KB |
testcase_04 | AC | 12 ms
6,816 KB |
testcase_05 | AC | 12 ms
6,816 KB |
testcase_06 | AC | 14 ms
6,816 KB |
testcase_07 | AC | 14 ms
6,820 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 12 ms
6,820 KB |
testcase_11 | AC | 11 ms
6,816 KB |
testcase_12 | AC | 14 ms
6,816 KB |
testcase_13 | AC | 13 ms
6,816 KB |
testcase_14 | WA | - |
testcase_15 | AC | 14 ms
6,816 KB |
testcase_16 | WA | - |
testcase_17 | AC | 13 ms
6,816 KB |
testcase_18 | AC | 10 ms
6,820 KB |
testcase_19 | AC | 4 ms
6,816 KB |
testcase_20 | WA | - |
testcase_21 | AC | 4 ms
6,816 KB |
testcase_22 | AC | 8 ms
6,820 KB |
testcase_23 | AC | 10 ms
6,816 KB |
testcase_24 | AC | 12 ms
6,820 KB |
testcase_25 | AC | 13 ms
6,820 KB |
testcase_26 | AC | 5 ms
6,820 KB |
testcase_27 | AC | 5 ms
6,816 KB |
testcase_28 | AC | 2 ms
6,820 KB |
testcase_29 | AC | 2 ms
6,820 KB |
testcase_30 | AC | 14 ms
6,820 KB |
testcase_31 | WA | - |
testcase_32 | AC | 14 ms
6,820 KB |
testcase_33 | AC | 13 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int LOG = 13; const long long INF = 1000000000000000000; int main(){ int N, K; cin >> N >> K; vector<int> R(N); vector<long long> X(N); for (int i = 0; i < N; i++){ cin >> R[i] >> X[i]; } vector<vector<pair<long long, int>>> E(N + 1); for (int i = 0; i < N; i++){ E[i].push_back(make_pair(X[i], R[i])); E[R[i]].push_back(make_pair(-X[i], i)); } vector<int> d(N + 1, 0); vector<long long> s(N + 1, 0); for (int i = N - 1; i >= 0; i--){ d[i] = d[R[i]] + 1; s[i] = s[R[i]] + X[i]; } vector<vector<int>> pp(LOG, vector<int>(N + 1, -1)); for (int i = 0; i < N; i++){ pp[0][i] = R[i]; } for (int i = 0; i < LOG - 1; i++){ for (int j = 0; j <= N; j++){ if (pp[i][j] != -1){ pp[i + 1][j] = pp[i][pp[i][j]]; } } } auto climb = [&](int v, int k){ for (int i = 0; i < LOG; i++){ if ((k >> i & 1) == 1){ v = pp[i][v]; } } return v; }; auto lca = [&](int u, int v){ if (d[u] > d[v]){ swap(u, v); } v = climb(v, d[v] - d[u]); if (u == v){ return u; } for (int i = LOG - 1; i >= 0; i--){ if (pp[i][u] != pp[i][v]){ u = pp[i][u]; v = pp[i][v]; } } return R[u]; }; vector<int> add(N + 1, 0); int add_all = 0; vector<vector<long long>> mn(LOG, vector<long long>(N + 1, -INF)); vector<vector<long long>> mx(LOG, vector<long long>(N + 1, INF)); auto path_chmax = [&](int u, int v, long long x){ if (u == v){ return; } int D = 31 - __builtin_clz(d[u] - d[v]); mn[D][u] = max(mn[D][u], x); int p = climb(u, (d[u] - d[v]) - (1 << D)); mn[D][p] = max(mn[D][p], x); }; auto path_chmin = [&](int u, int v, long long x){ if (u == v){ return; } int D = 31 - __builtin_clz(d[u] - d[v]); mx[D][u] = min(mx[D][u], x); int p = climb(u, (d[u] - d[v]) - (1 << D)); mx[D][p] = min(mx[D][p], x); }; for (int i = 0; i < N; i++){ int w = lca(i, i + 1); if (s[i] - s[i + 1] < 0 || s[i] - s[i + 1] > K){ add_all++; add[i]--; add[i + 1]--; add[w] += 2; } path_chmax(i, w, -s[i] + s[i + 1]); path_chmin(i, w, -s[i] + s[i + 1] + K); path_chmax(i + 1, w, s[i] - s[i + 1] - K); path_chmin(i + 1, w, s[i] - s[i + 1]); } for (int i = LOG - 2; i >= 0; i--){ for (int j = 0; j < N; j++){ mx[i][j] = min(mx[i][j], mx[i + 1][j]); mn[i][j] = max(mn[i][j], mn[i + 1][j]); if (pp[i][j] != -1){ mx[i][j] = min(mx[i][j], mx[i + 1][pp[i][j]]); mn[i][j] = max(mn[i][j], mn[i + 1][pp[i][j]]); } } } vector<bool> ok(N, true); for (int i = 0; i < N; i++){ add[R[i]] += add[i]; if (add[i] + add_all > 0){ ok[i] = false; } } for (int i = 0; i < N; i++){ if (mn[0][i] > mx[0][i]){ ok[i] = false; } } for (int i = 0; i < N; i++){ if (ok[i]){ cout << "Yes" << endl; } else { cout << "No" << endl; } } }