結果

問題 No.1014 competitive fighting
ユーザー ミドリムシミドリムシ
提出日時 2020-03-20 22:59:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,010 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 183,604 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-05-08 23:56:25
合計ジャッジ時間 12,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 276 ms
11,648 KB
testcase_06 AC 287 ms
11,648 KB
testcase_07 AC 283 ms
11,776 KB
testcase_08 AC 281 ms
11,648 KB
testcase_09 AC 290 ms
11,520 KB
testcase_10 AC 230 ms
11,648 KB
testcase_11 AC 275 ms
11,648 KB
testcase_12 AC 289 ms
11,648 KB
testcase_13 AC 138 ms
7,296 KB
testcase_14 AC 123 ms
7,296 KB
testcase_15 AC 145 ms
7,552 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 53 ms
5,376 KB
testcase_18 AC 238 ms
10,880 KB
testcase_19 AC 280 ms
11,648 KB
testcase_20 AC 99 ms
6,784 KB
testcase_21 AC 214 ms
10,624 KB
testcase_22 AC 174 ms
7,936 KB
testcase_23 AC 70 ms
5,376 KB
testcase_24 AC 72 ms
5,376 KB
testcase_25 AC 18 ms
5,376 KB
testcase_26 AC 211 ms
10,496 KB
testcase_27 AC 55 ms
5,376 KB
testcase_28 AC 60 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 278 ms
11,520 KB
testcase_31 AC 218 ms
10,624 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 18 ms
5,376 KB
testcase_34 AC 200 ms
10,496 KB
testcase_35 WA -
testcase_36 AC 182 ms
10,240 KB
testcase_37 AC 8 ms
5,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 161 ms
7,680 KB
testcase_41 AC 115 ms
7,040 KB
testcase_42 AC 261 ms
11,392 KB
testcase_43 AC 16 ms
5,376 KB
testcase_44 AC 237 ms
11,008 KB
testcase_45 WA -
testcase_46 AC 26 ms
5,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 10 ms
5,376 KB
testcase_50 AC 245 ms
11,264 KB
testcase_51 AC 147 ms
7,552 KB
testcase_52 AC 11 ms
5,376 KB
testcase_53 AC 295 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using lint128 = __int128_t;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void assert_NO(T condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
template<class T> inline void assert_No(T condition){ if(!condition){ cout << "No" << endl; exit(0); } }
template<class T> inline void assert_minus_1(T condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
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; }
inline int at(lint x, int k){ return (x >> k) & 1; }
random_device rnd;
#define rep(i, n) for(int i = 0; i < n; i++)

template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;
    
    int sz;
    vector< Monoid > seg;
    
    const F f;
    const Monoid M1;
    
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }
    
    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }
    
    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    
    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    
    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }
    
    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
    
    template< typename C >
    int find_subtree(int a, const C &check, Monoid &M, bool type) {
        while(a < sz) {
            Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
            if(check(nxt)) a = 2 * a + type;
            else M = nxt, a = 2 * a + 1 - type;
        }
        return a - sz;
    }
    
    
    template< typename C >
    int find_first(int a, const C &check) {
        Monoid L = M1;
        if(a <= 0) {
            if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
            return -1;
        }
        int b = sz;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) {
                Monoid nxt = f(L, seg[a]);
                if(check(nxt)) return find_subtree(a, check, L, false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }
    
    template< typename C >
    int find_last(int b, const C &check) {
        Monoid R = M1;
        if(b >= sz) {
            if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for(b += sz; a < b; a >>= 1, b >>= 1) {
            if(b & 1) {
                Monoid nxt = f(seg[--b], R);
                if(check(nxt)) return find_subtree(b, check, R, true);
                R = nxt;
            }
        }
        return -1;
    }
};

int main(){
    int N;
    cin >> N;
    tuple<lint, lint, lint, int> skill[N];
    rep(i, N){
        lint A, B, C;
        cin >> A >> B >> C;
        skill[i] = {A, B - C, B, i};
    }
    sort(skill, skill + N);
    SegmentTree<lint> seg(N, [](lint a, lint b) { return max(a, b); }, LONG_LONG_MIN);
    rep(i, N){
        seg.set(i, get<1>(skill[i]));
    }
    seg.build();
    int right[N];
    bool is_ban[N];
    memset(is_ban, 0, sizeof(is_ban));
    rep(i, N){
        auto t = tuple<lint, lint, lint, int>(get<1>(skill[i]), LONG_LONG_MAX, 0, 0);
        right[i] = int(upper_bound(skill, skill + N, t) - skill);
        lint P_max;
        if(i < right[i]){
            P_max = max(seg.query(0, i), seg.query(i + 1, right[i]));
        }else{
            P_max = seg.query(0, right[i]);
        }
        is_ban[i] = (get<0>(skill[i]) <= P_max);
    }
    const lint INF = 1e18;
    SegmentTree<lint> power(N, [](lint a, lint b) { return max(a, b); }, 0);
    rep(i, N){
        if(is_ban[i]){
            power.set(i, INF);
        }
    }
    power.build();
    lint ans[N];
    rep(i, N){
        lint this_power;
        if(is_ban[i]){
            this_power = INF;
        }else{
            this_power = power.query(0, right[i]);
            if(this_power != INF){
                this_power += get<2>(skill[i]);
            }
            power.update(i, this_power);
        }
        ans[get<3>(skill[i])] = this_power;
    }
    rep(i, N){
        if(ans[i] == INF){
            cout << "BAN" << endl;
        }else{
            cout << ans[i] << endl;
        }
    }
}

0