結果

問題 No.1014 competitive fighting
ユーザー NOSSNOSS
提出日時 2020-03-20 23:46:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,068 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 187,640 KB
実行使用メモリ 13,668 KB
最終ジャッジ日時 2023-08-22 03:30:29
合計ジャッジ時間 17,528 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 288 ms
13,596 KB
testcase_06 AC 290 ms
13,548 KB
testcase_07 AC 288 ms
13,644 KB
testcase_08 AC 290 ms
13,580 KB
testcase_09 AC 286 ms
13,628 KB
testcase_10 AC 214 ms
13,608 KB
testcase_11 AC 275 ms
13,596 KB
testcase_12 AC 289 ms
13,668 KB
testcase_13 AC 135 ms
8,136 KB
testcase_14 AC 123 ms
7,796 KB
testcase_15 AC 147 ms
8,584 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 53 ms
5,160 KB
testcase_18 AC 238 ms
11,964 KB
testcase_19 AC 281 ms
13,328 KB
testcase_20 AC 99 ms
6,948 KB
testcase_21 AC 212 ms
11,476 KB
testcase_22 AC 173 ms
9,328 KB
testcase_23 AC 71 ms
5,700 KB
testcase_24 AC 72 ms
5,748 KB
testcase_25 AC 18 ms
4,380 KB
testcase_26 AC 209 ms
11,176 KB
testcase_27 AC 53 ms
5,104 KB
testcase_28 AC 59 ms
5,488 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 279 ms
13,220 KB
testcase_31 AC 224 ms
11,824 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 18 ms
4,376 KB
testcase_34 AC 209 ms
11,460 KB
testcase_35 WA -
testcase_36 AC 189 ms
10,648 KB
testcase_37 AC 8 ms
4,380 KB
testcase_38 AC 171 ms
9,388 KB
testcase_39 AC 88 ms
6,280 KB
testcase_40 AC 171 ms
9,112 KB
testcase_41 AC 118 ms
7,476 KB
testcase_42 AC 267 ms
13,064 KB
testcase_43 WA -
testcase_44 AC 245 ms
12,256 KB
testcase_45 WA -
testcase_46 AC 26 ms
4,380 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 253 ms
12,820 KB
testcase_51 AC 147 ms
8,580 KB
testcase_52 AC 10 ms
4,380 KB
testcase_53 AC 288 ms
13,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

template <typename Monoid>
struct SegmentTree{
private:
    using F = function<Monoid(Monoid, Monoid)>;
    int N;
    vector<Monoid> node;
    F f;
    Monoid e;  // identity element

public:
    SegmentTree(){}
    SegmentTree(F f, Monoid e):f(f), e(e){}
    void init(int sz){
        N = 1;
        while(N < sz) N <<= 1;
        node.assign(2*N-1, e);
    }
    void build(vector<Monoid>& v){
        int sz = int(v.size());
        init(sz);
        for(int i=0; i<sz; i++){
            node[i+N-1] = v[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }
    void update(int k, Monoid x){
        k += N-1;
        node[k] = x;
        while(k > 0){
            k = (k-1)/2;
            node[k] = f(node[2*k+1], node[2*k+2]);
        }
    }
    // [a,b)
    Monoid query(int a, int b){return query(a, b, 0, 0, N);}
    Monoid query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a) return e;
        if(a <= l && r <= b) return node[k];
        Monoid vl, vr;
        vl = query(a, b, 2*k+1, l, (l+r)/2);
        vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

SegmentTree<ll> rmq([](ll a, ll b){return max(a,b);},0);

int main(){
    int N;
    cin >> N;
    vector<P> A(N);
    vector<P3> ord(N);
    vector<ll> B(N), C(N), rev(N);
    for(int i=0;i<N;i++){
        cin >> A[i].first >> B[i] >> C[i];
        A[i].second = i;;
    }
    sort(A.begin(), A.end());
    vector<ll> r(N);  // [0,r[i])
    for(int i=0;i<N;i++){
        int k = A[i].second;
        rev[k] = i;
        r[i] = upper_bound(A.begin(), A.end(), P(B[k]-C[k],N)) - A.begin();
        ord[i] = P3(P(r[i], A[i].first),k);
    }
    sort(ord.begin(), ord.end());
    rmq.build(r);
    vector<bool> ban(N);
    int banmin = N+1;
    for(int i=0;i<N;i++){
        if(r[i] > banmin){
            ban[i] = true;
        }
        else if(r[i] <= i){
            if(rmq.query(0,r[i]) > i){
                ban[i] = true;
                banmin = min(banmin, i);
            }
        }else{
            if(max(rmq.query(0,i), rmq.query(i+1,r[i])) > i){
                ban[i] = true;
                banmin = min(banmin, i);
            }
        }
    }
    vector<ll> ans(N), tmp(N);
    rmq.init(N);
    // TODO ちゃんとトポソ順に更新する
    for(int i=0;i<N;i++){
        int idx = ord[i].second;
        int k = rev[idx];
        if(ban[k]) continue;
        ans[idx] = rmq.query(0,r[k]) + B[idx];
        tmp[k] = ans[idx];

        rmq.update(k, ans[idx]);
    }
    for(int i=0;i<N;i++){
        if(ban[rev[i]]){
            cout << "BAN" << endl;
        }else{
            cout << ans[i] << endl;
        }
    }
    return 0;
}
0