結果

問題 No.1014 competitive fighting
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-03-21 12:34:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 3,408 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 219,192 KB
実行使用メモリ 42,988 KB
最終ジャッジ日時 2023-09-21 19:22:54
合計ジャッジ時間 8,745 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,704 KB
testcase_01 AC 3 ms
7,700 KB
testcase_02 AC 3 ms
7,768 KB
testcase_03 AC 3 ms
7,700 KB
testcase_04 AC 3 ms
7,552 KB
testcase_05 AC 124 ms
26,552 KB
testcase_06 AC 124 ms
26,644 KB
testcase_07 AC 126 ms
26,540 KB
testcase_08 AC 125 ms
26,616 KB
testcase_09 AC 126 ms
26,640 KB
testcase_10 AC 136 ms
42,988 KB
testcase_11 AC 75 ms
19,748 KB
testcase_12 AC 127 ms
26,620 KB
testcase_13 AC 59 ms
16,700 KB
testcase_14 AC 55 ms
16,148 KB
testcase_15 AC 64 ms
17,048 KB
testcase_16 AC 6 ms
7,836 KB
testcase_17 AC 24 ms
11,228 KB
testcase_18 AC 107 ms
24,688 KB
testcase_19 AC 125 ms
26,384 KB
testcase_20 AC 46 ms
15,416 KB
testcase_21 AC 98 ms
24,224 KB
testcase_22 AC 74 ms
17,792 KB
testcase_23 AC 31 ms
11,860 KB
testcase_24 AC 32 ms
11,892 KB
testcase_25 AC 10 ms
8,296 KB
testcase_26 AC 96 ms
23,892 KB
testcase_27 AC 25 ms
11,408 KB
testcase_28 AC 28 ms
11,552 KB
testcase_29 AC 4 ms
7,684 KB
testcase_30 AC 119 ms
26,284 KB
testcase_31 AC 97 ms
24,276 KB
testcase_32 AC 4 ms
7,696 KB
testcase_33 AC 8 ms
8,316 KB
testcase_34 AC 62 ms
19,336 KB
testcase_35 AC 74 ms
19,688 KB
testcase_36 AC 58 ms
18,968 KB
testcase_37 AC 5 ms
7,768 KB
testcase_38 AC 47 ms
13,860 KB
testcase_39 AC 25 ms
10,508 KB
testcase_40 AC 45 ms
13,892 KB
testcase_41 AC 35 ms
13,448 KB
testcase_42 AC 72 ms
19,776 KB
testcase_43 AC 8 ms
8,164 KB
testcase_44 AC 67 ms
19,496 KB
testcase_45 AC 41 ms
13,524 KB
testcase_46 AC 11 ms
8,916 KB
testcase_47 AC 24 ms
10,436 KB
testcase_48 AC 60 ms
19,204 KB
testcase_49 AC 6 ms
7,904 KB
testcase_50 AC 72 ms
19,420 KB
testcase_51 AC 41 ms
13,608 KB
testcase_52 AC 5 ms
7,840 KB
testcase_53 AC 123 ms
26,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/



struct DirectedGraphRangeEdge {
    int NV;
    vector<vector<int>> E;
    void init(int n) {
        NV = 1; while (NV < n) NV *= 2;
        E.resize(NV * 2);
        rep(i, 1, NV) {
            E[i].push_back(i * 2);
            E[i].push_back(i * 2 + 1);
        }
    }
    // [x, y)
    void add(int from, int x, int y) { add(from + NV, x, y, 0, NV, 1); }
    void add(int from, int x, int y, int l, int r, int k) {
        if (r <= x || y <= l) return;
        if (x <= l && r <= y) {
            E[from].push_back(k);
            return;
        }
        add(from, x, y, l, (l + r) / 2, k * 2);
        add(from, x, y, (l + r) / 2, r, k * 2 + 1);
    }
};




int N;
DirectedGraphRangeEdge dgre;
vector<tuple<int, int, int, int>> ABCi;
ll ans[101010];
//---------------------------------------------------------------------------------------------------
ll memo[1 << 19]; // -1: not visited      -2: pending     0<=: cached    infl: BAN
ll dfs(int cu) {
    if (0 <= memo[cu]) return memo[cu];
    if (memo[cu] == -2) return memo[cu] = infl;
    memo[cu] = -2;

    ll res = 0;
    fore(to, dgre.E[cu]) chmax(res, dfs(to));

    if (res == infl) return infl;
    if (dgre.NV <= cu) res += get<1>(ABCi[cu - dgre.NV]);
    return memo[cu] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    dgre.init(N);
    rep(i, 0, N) {
        int a, b, c; cin >> a >> b >> c;
        ABCi.push_back(make_tuple(a, b, c, i));
    }
    sort(all(ABCi));

    rep(i, 0, N) {
        int b, c, _; tie(_, b, c, _) = ABCi[i];

        int idx = lower_bound(all(ABCi), make_tuple(b - c + 1, -1, -1, -1)) - ABCi.begin();

        if (i < idx) {
            if (0 < i) dgre.add(i, 0, i);
            if (i + 1 < idx) dgre.add(i, i + 1, idx);
        } else dgre.add(i, 0, idx);
    }

    rep(i, 0, 1 << 19) memo[i] = -1;
    rep(i, 0, N) ans[get<3>(ABCi[i])] = dfs(i + dgre.NV);

    rep(i, 0, N) {
        if (ans[i] == infl) printf("BAN\n");
        else printf("%lld\n", ans[i]);
    }
}





0