結果

問題 No.1014 competitive fighting
ユーザー IKyoproIKyopro
提出日時 2020-03-22 22:59:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 2,441 bytes
コンパイル時間 3,188 ms
コンパイル使用メモリ 220,256 KB
実行使用メモリ 15,308 KB
最終ジャッジ日時 2023-09-21 19:24:27
合計ジャッジ時間 10,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 155 ms
15,308 KB
testcase_06 AC 156 ms
15,304 KB
testcase_07 AC 159 ms
15,232 KB
testcase_08 AC 156 ms
15,264 KB
testcase_09 AC 152 ms
15,276 KB
testcase_10 AC 59 ms
10,620 KB
testcase_11 AC 65 ms
8,484 KB
testcase_12 AC 154 ms
15,232 KB
testcase_13 AC 64 ms
8,988 KB
testcase_14 AC 58 ms
8,592 KB
testcase_15 AC 71 ms
9,448 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 23 ms
5,476 KB
testcase_18 AC 123 ms
13,304 KB
testcase_19 AC 148 ms
14,936 KB
testcase_20 AC 45 ms
7,672 KB
testcase_21 AC 106 ms
12,552 KB
testcase_22 AC 85 ms
10,364 KB
testcase_23 AC 30 ms
5,944 KB
testcase_24 AC 31 ms
6,216 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 104 ms
12,412 KB
testcase_27 AC 22 ms
5,464 KB
testcase_28 AC 25 ms
5,596 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 146 ms
14,936 KB
testcase_31 AC 111 ms
12,792 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 7 ms
4,380 KB
testcase_34 AC 92 ms
12,300 KB
testcase_35 AC 129 ms
14,752 KB
testcase_36 AC 83 ms
11,580 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 74 ms
9,824 KB
testcase_39 AC 35 ms
6,900 KB
testcase_40 AC 76 ms
9,928 KB
testcase_41 AC 48 ms
8,060 KB
testcase_42 AC 121 ms
14,312 KB
testcase_43 AC 6 ms
4,380 KB
testcase_44 AC 108 ms
13,228 KB
testcase_45 AC 60 ms
9,112 KB
testcase_46 AC 10 ms
4,376 KB
testcase_47 AC 31 ms
6,388 KB
testcase_48 AC 88 ms
11,648 KB
testcase_49 AC 4 ms
4,376 KB
testcase_50 AC 114 ms
13,812 KB
testcase_51 AC 61 ms
9,284 KB
testcase_52 AC 4 ms
4,380 KB
testcase_53 AC 155 ms
15,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename F>
class SegmentTree{
private:
    int sz;
    vector<Monoid> seg;
    const F op;//演算
    const Monoid e;//単位元
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<=n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

constexpr ll inf = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N),B(N),C(N);
    map<ll,ll> cnt;
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i] >> C[i];
        cnt[A[i]]++;
    }
    vec<int> id(N);
    iota(id.begin(),id.end(),0);
    sort(id.begin(),id.end(),[&](int i,int j){
        if(A[i]!=A[j]) return A[i]<A[j];
        else return B[i]-C[i]<B[j]-C[j];
    });
    vec<ll> dp(N,-1);
    auto mymax = [](ll a,ll b){return max(a,b);};
    SegmentTree<ll,decltype(mymax)> seg(N,mymax,0);
    for(int i=0;i<N;i++) seg.set(i,inf);
    seg.build();
    priority_queue<Pa<ll,ll>,vec<Pa<ll,ll>>,greater<Pa<ll,ll>>> Q;
    for(int i=0;i<N;i++){
        Q.push({B[id[i]]-C[id[i]],i});
        ll ne = (i==N-1? inf:A[id[i+1]]);
        while(!Q.empty()){
            auto p = Q.top();
            if(p.first>=ne) break;
            Q.pop();
            int r = partition_point(id.begin(),id.end(),[&](int x){return p.first>=A[x];})-id.begin();
            seg.update(p.second,0);
            dp[id[p.second]] = min(inf,B[id[p.second]]+seg.query(0,r));
            seg.update(p.second,dp[id[p.second]]);
        }
    }
    for(auto& x:dp){
        if(x==inf) cout << "BAN\n";
        else cout << x << "\n";
    }
}
0