結果

問題 No.759 悪くない忘年会にしような!
ユーザー はむこ
提出日時 2018-12-03 11:55:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 2,040 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 197,096 KB
実行使用メモリ 29,324 KB
最終ジャッジ日時 2024-09-13 12:01:27
合計ジャッジ時間 7,975 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 64
権限があれば一括ダウンロードができます

ソースコード

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>;

template<class T>
struct SegmentTreeMax {
    int n;
    T inf;
    vector<T> dat;
    SegmentTreeMax(int n_ = 0) : n(n_){
        inf = numeric_limits<T>::min();
        for(n = 1; n < n_; n <<= 1);
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(r <= l || w == 0) return inf;
        if(r - l == w) return dat[v]; // assert(l == 0 && r == w);
        int m = w/2;
        return max(query(v*2, m, l, min(r,m)), query(v*2+1, m, max(0,l-m), r-m));
    }
    void update(int i, const T &x){
        chmax(dat[i+=n], x);
        for(; i!=1; i/=2) dat[i/2] = max(dat[i], dat[i^1]);
    }
    T query(int l, int r){ return query(1,n,l,r); }
    size_t size() const { return n; }
    T operator [] (const int &idx) { return query(idx, idx + 1); }
};

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0);
    SegmentTreeMax<int> s(1e5+10);
    ll n; cin >> n; 

    vector<vector<P>> g(1e5+10);
    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, 1e5+10)) {
                next.pb(x);
                ret.pb({i, x.fi, x.se});
            }
            s.update(x.fi, x.se);
        }
    }

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

    return 0;
}
0