結果

問題 No.1014 competitive fighting
ユーザー betrue12betrue12
提出日時 2020-03-20 22:51:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 2,834 bytes
コンパイル時間 3,234 ms
コンパイル使用メモリ 221,044 KB
実行使用メモリ 24,392 KB
最終ジャッジ日時 2023-09-21 19:20:13
合計ジャッジ時間 16,637 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 356 ms
21,924 KB
testcase_06 AC 357 ms
21,528 KB
testcase_07 AC 366 ms
22,096 KB
testcase_08 AC 366 ms
22,220 KB
testcase_09 AC 366 ms
21,832 KB
testcase_10 AC 286 ms
24,392 KB
testcase_11 AC 324 ms
21,232 KB
testcase_12 AC 363 ms
21,824 KB
testcase_13 AC 160 ms
11,828 KB
testcase_14 AC 148 ms
11,696 KB
testcase_15 AC 176 ms
12,656 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 65 ms
6,980 KB
testcase_18 AC 291 ms
20,028 KB
testcase_19 AC 359 ms
21,208 KB
testcase_20 AC 118 ms
10,880 KB
testcase_21 AC 259 ms
19,300 KB
testcase_22 AC 208 ms
13,924 KB
testcase_23 AC 82 ms
7,608 KB
testcase_24 AC 86 ms
7,820 KB
testcase_25 AC 20 ms
4,380 KB
testcase_26 AC 258 ms
17,880 KB
testcase_27 AC 63 ms
6,840 KB
testcase_28 AC 70 ms
7,288 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 344 ms
21,896 KB
testcase_31 AC 268 ms
18,272 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 20 ms
4,380 KB
testcase_34 AC 255 ms
19,240 KB
testcase_35 AC 343 ms
21,468 KB
testcase_36 AC 232 ms
16,996 KB
testcase_37 AC 9 ms
4,376 KB
testcase_38 AC 211 ms
13,552 KB
testcase_39 AC 108 ms
8,512 KB
testcase_40 AC 211 ms
13,388 KB
testcase_41 AC 146 ms
10,860 KB
testcase_42 AC 341 ms
20,292 KB
testcase_43 AC 18 ms
4,376 KB
testcase_44 AC 301 ms
20,080 KB
testcase_45 AC 173 ms
12,468 KB
testcase_46 AC 30 ms
4,828 KB
testcase_47 AC 96 ms
8,000 KB
testcase_48 AC 240 ms
17,104 KB
testcase_49 AC 11 ms
4,380 KB
testcase_50 AC 309 ms
20,024 KB
testcase_51 AC 180 ms
12,480 KB
testcase_52 AC 11 ms
4,376 KB
testcase_53 AC 361 ms
21,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct Segtree {
    int n, n_org;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        n_org = n_input;
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void build(vector<T>& A){
        for(int k=0; k<int(A.size()); k++) dat[k+n-1] = A[k];
        for(int k=n-2; k>=0; k--) dat[k] = f(dat[2*k+1], dat[2*k+2]);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N), D(N);
    // {pos, c, i}
    // c : Aなら0, Dなら1
    vector<vector<int>> X;
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i] >> C[i];
        D[i] = B[i] - C[i];
        X.push_back({A[i], 0, i});
        X.push_back({D[i], 1, i});
    }
    sort(X.begin(), X.end());
    bitset<100000> inf, a_done, d_done;
    multiset<int> st;
    st.insert(2e9);
    bool inf_now = false;
    for(auto& v : X){
        int t = v[1], i = v[2];
        if(t == 0){
            if(D[i] >= *st.begin()){
                inf_now = true;
            }
            a_done[i] = 1;
            if(!d_done[i]) st.insert(A[i]);
        }else{
            if(inf_now) inf[i] = 1;
            d_done[i] = 1;
            if(a_done[i]) st.erase(st.lower_bound(A[i]));
        }
    }

    vector<int> apos(N), dpos(N);
    for(int i=0; i<2*N; i++){
        if(X[i][1] == 0){
            apos[X[i][2]] = i;
        }else{
            dpos[X[i][2]] = i;
        }
    }

    Segtree<int64_t> segt(2*N, [](auto a, auto b){ return max(a, b); }, 0);

    vector<int64_t> ans(N, -1);
    for(int i=0; i<N; i++) if(inf[i]) ans[i] = 1e18;
    for(auto& v : X){
        int i = v[2];
        if(ans[i] == -1){
            ans[i] = B[i] + segt.between(0, dpos[i]);
            if(ans[i] > 1e18) ans[i] = 1e18;
        }
        segt.update(apos[i], ans[i]);
    }
    for(int i=0; i<N; i++){
        if(ans[i] == 1e18){
            cout << "BAN" << endl;
        }else{
            cout << ans[i] << endl;
        }
    }
    return 0;
}
0