結果

問題 No.759 悪くない忘年会にしような!
ユーザー はむこはむこ
提出日時 2018-12-03 11:01:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 4,557 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 194,520 KB
実行使用メモリ 36,528 KB
最終ジャッジ日時 2023-10-11 13:13:25
合計ジャッジ時間 9,969 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,896 KB
testcase_01 AC 7 ms
13,916 KB
testcase_02 AC 7 ms
13,912 KB
testcase_03 AC 7 ms
13,908 KB
testcase_04 AC 7 ms
14,072 KB
testcase_05 AC 7 ms
13,964 KB
testcase_06 AC 7 ms
14,180 KB
testcase_07 AC 7 ms
13,932 KB
testcase_08 AC 7 ms
14,092 KB
testcase_09 AC 7 ms
13,956 KB
testcase_10 AC 6 ms
13,896 KB
testcase_11 AC 8 ms
13,904 KB
testcase_12 AC 6 ms
14,104 KB
testcase_13 AC 7 ms
14,004 KB
testcase_14 AC 7 ms
13,860 KB
testcase_15 AC 7 ms
13,900 KB
testcase_16 AC 7 ms
13,960 KB
testcase_17 AC 7 ms
13,900 KB
testcase_18 AC 6 ms
13,912 KB
testcase_19 AC 6 ms
14,044 KB
testcase_20 AC 7 ms
14,024 KB
testcase_21 AC 7 ms
14,076 KB
testcase_22 AC 7 ms
13,908 KB
testcase_23 AC 7 ms
14,032 KB
testcase_24 AC 7 ms
14,004 KB
testcase_25 AC 7 ms
14,036 KB
testcase_26 AC 7 ms
13,900 KB
testcase_27 AC 6 ms
13,976 KB
testcase_28 AC 7 ms
13,960 KB
testcase_29 AC 6 ms
13,952 KB
testcase_30 AC 8 ms
13,900 KB
testcase_31 AC 7 ms
13,904 KB
testcase_32 AC 6 ms
13,896 KB
testcase_33 AC 21 ms
14,948 KB
testcase_34 AC 9 ms
13,960 KB
testcase_35 AC 15 ms
14,476 KB
testcase_36 AC 21 ms
15,020 KB
testcase_37 AC 10 ms
14,284 KB
testcase_38 AC 22 ms
15,232 KB
testcase_39 AC 11 ms
14,228 KB
testcase_40 AC 18 ms
14,788 KB
testcase_41 AC 20 ms
14,964 KB
testcase_42 AC 24 ms
15,080 KB
testcase_43 AC 25 ms
15,272 KB
testcase_44 AC 214 ms
27,148 KB
testcase_45 AC 217 ms
27,232 KB
testcase_46 AC 217 ms
27,044 KB
testcase_47 AC 220 ms
27,228 KB
testcase_48 AC 217 ms
27,224 KB
testcase_49 AC 25 ms
15,284 KB
testcase_50 AC 25 ms
15,464 KB
testcase_51 AC 25 ms
15,228 KB
testcase_52 AC 25 ms
15,220 KB
testcase_53 AC 217 ms
27,100 KB
testcase_54 AC 217 ms
27,312 KB
testcase_55 AC 219 ms
27,236 KB
testcase_56 AC 215 ms
27,104 KB
testcase_57 AC 213 ms
27,044 KB
testcase_58 AC 218 ms
27,236 KB
testcase_59 AC 226 ms
27,032 KB
testcase_60 AC 215 ms
27,168 KB
testcase_61 AC 214 ms
27,220 KB
testcase_62 AC 214 ms
27,036 KB
testcase_63 AC 419 ms
36,528 KB
testcase_64 AC 420 ms
36,520 KB
testcase_65 AC 209 ms
26,528 KB
testcase_66 AC 389 ms
35,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;

struct Pool {
    int pos;
    char mem[(ll)2e8]; // 200MB
    Pool(){ free(); }
    template<class T>
        T *fetch(size_t n = 1) {
            T *res = (T*)(mem + pos);
            pos += sizeof(T)*n;
            return res;
        }
    void free(){ pos = 0; }
}; Pool pool;

template<class T>
class AssosiativeOperator {
public:
    AssosiativeOperator(void) { }
    T T0; 
    virtual T op(T a, T b) = 0;
    T L0;
    virtual T op_lazy(T a, T b) = 0;
    virtual T resolve_lazy(T d, T l, int nl, int nr) = 0;
};

template<class T>
class AssosiativeOperatorMax : public AssosiativeOperator<T> {
public:
    AssosiativeOperatorMax(void) { AssosiativeOperator<T>::T0 = -100; AssosiativeOperator<T>::L0 = 0; }
    virtual T op(T a, T b) { return max(a, b); } // Range Max
    virtual T op_lazy(T a, T b) { return max(a, b); } // Range Add
    virtual T resolve_lazy(T d, T l, int nl, int nr) { return max(d, l); } // 全部上がってるので、子によらず増える
};

template<class T>
class SegmentTree {
public:
    T *dat, *lazy; 
    AssosiativeOperator<T>* op;
    int n = 1;
    int bits = 0;
    const size_t size_; 
    int ql, qr;
    bool enable_range_update_flag = true;
    bool enable_point_update_with_op_flag = false;
    SegmentTree(int n_, AssosiativeOperator<T>* op) : size_(n_) {
        this->op = op;
        while(n < n_) { n <<= 1; bits++; }
        dat = pool.fetch<T>(n+n);
        lazy = pool.fetch<T>(n+n);
        fill_n(dat, n*4, this->op->T0);
    }
    void inline pushdown(int v, int nl, int nr){
        assert(enable_range_update_flag);
        dat[v] = op->resolve_lazy(dat[v], lazy[v], nl, nr);
        if(v < n){ // 子がいれば
            lazy[v<<1] = op->op_lazy(lazy[v<<1], lazy[v]);
            lazy[v<<1|1] = op->op_lazy(lazy[v<<1|1], lazy[v]);
        }
        lazy[v] = op->L0;
    }
    void inline pullup(int v){
        assert(enable_range_update_flag);
        dat[v] = op->op(dat[v<<1], dat[v<<1|1]); 
    }
    void update(int v, const T &x){
        v += n;
        if (enable_point_update_with_op_flag) 
            dat[v] = op->op(dat[v], x);
        else
            dat[v] = x;
        while (v){
            v = v >> 1;
            dat[v] = op->op(dat[v<<1], dat[v<<1|1]); 
        }
    }
    void update(int n, int nl, int nr, const T &x){
        assert(enable_range_update_flag);
        pushdown(n, nl, nr);
        if(nr <= ql || qr <= nl) return;
        if(ql <= nl && nr <= qr) {
            lazy[n] = op->op_lazy(lazy[n], x);
            pushdown(n, nl, nr);
            return;
        }
        int m = (nl + nr) / 2;
        update(n<<1, nl, m, x);
        update(n<<1|1, m, nr, x);
        pullup(n);
    }
    void update(int l, int r, const T &x){
        ql = l; qr = r;
        return update(1, 0, n, x);
    }
    T query(int n, int nl, int nr){
        if (enable_range_update_flag) pushdown(n, nl, nr);
        if(nr <= ql || qr <= nl) return op->T0;
        if(ql <= nl && nr <= qr) return dat[n]; 
        if (enable_range_update_flag) pullup(n);
        int m = (nl + nr) / 2;
        return op->op(query(n<<1, nl, m), query(n<<1|1, m, nr)); 
    }
    T query(int l, int r){
        ql = l; qr = r;
        return query(1, 0, n);
    }
};


int main(void) {
    ios::sync_with_stdio(false); cin.tie(0);
    SegmentTree<int> s(2e5, new AssosiativeOperatorMax<int>());
    ll n; cin >> n;

    vector<vector<P>> g(2e5);
    map<vll, ll> memo;
    rep(i, n) {
        ll x, y, z; cin >> x >> y >> z;
        g[x].pb(P(y, z + 1));
        memo[{x, y, z + 1}] = i;
    }
    vector<vll> ret;
    for (ll i = g.size() - 1; i >= 0; i--) {
        sort(all(g[i]));
        reverse(all(g[i]));
        vector<P> next;
        for (auto x : g[i]) {
            if (x.se > s.query(x.fi, x.fi+1)) {
                next.pb(x);
                ret.pb({i, x.fi, x.se});
            }
            s.update(0, x.fi+1, x.se);
        }
    }

    set<ll> id;
    for (auto x : ret) {
        id.insert(memo[x]);
    }
    for (auto x : id) {
        cout << x + 1 << endl;
    }

    return 0;
}
0