結果

問題 No.759 悪くない忘年会にしような!
ユーザー はむこはむこ
提出日時 2018-12-03 10:21:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 12,470 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 185,144 KB
実行使用メモリ 34,848 KB
最終ジャッジ日時 2023-10-11 13:12:05
合計ジャッジ時間 8,295 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,084 KB
testcase_01 AC 6 ms
12,008 KB
testcase_02 AC 7 ms
12,076 KB
testcase_03 AC 6 ms
11,928 KB
testcase_04 AC 6 ms
12,116 KB
testcase_05 AC 7 ms
12,160 KB
testcase_06 AC 7 ms
12,008 KB
testcase_07 AC 7 ms
11,960 KB
testcase_08 AC 7 ms
11,960 KB
testcase_09 AC 7 ms
12,016 KB
testcase_10 AC 6 ms
12,084 KB
testcase_11 AC 6 ms
12,000 KB
testcase_12 AC 7 ms
12,020 KB
testcase_13 AC 6 ms
11,844 KB
testcase_14 AC 6 ms
11,896 KB
testcase_15 AC 6 ms
11,964 KB
testcase_16 AC 7 ms
12,016 KB
testcase_17 AC 6 ms
11,964 KB
testcase_18 WA -
testcase_19 AC 6 ms
12,004 KB
testcase_20 AC 6 ms
12,012 KB
testcase_21 WA -
testcase_22 AC 7 ms
12,064 KB
testcase_23 AC 6 ms
12,012 KB
testcase_24 AC 7 ms
12,192 KB
testcase_25 AC 7 ms
11,944 KB
testcase_26 AC 7 ms
12,160 KB
testcase_27 AC 7 ms
12,016 KB
testcase_28 AC 6 ms
11,956 KB
testcase_29 AC 5 ms
11,832 KB
testcase_30 AC 7 ms
11,952 KB
testcase_31 AC 6 ms
11,956 KB
testcase_32 AC 7 ms
12,056 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 AC 375 ms
34,636 KB
testcase_64 AC 383 ms
34,848 KB
testcase_65 AC 140 ms
24,552 KB
testcase_66 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
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>;
using ld = long double;  using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }

inline void input(int &v){ v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } // これを使うならば、tieとかを消して!!
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const unordered_set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U, typename V>  ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; }
template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;}
template <typename T, typename S, typename U> ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.front(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> unordered_map<T, ll> counter(vector<T> vec){unordered_map<T, ll> ret; for (auto&& x : vec) ret[x]++; return ret;};
string substr(string s, P x) {return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll& g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set<P> memo; rep(i, g.size())  rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << "    " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "")<< endl;  } ofs << "}" << endl; ofs.close(); system(((string)"dot -T png out.dot >" + filename).c_str()); }
size_t random_seed; namespace std { using argument_type = P; template<> struct hash<argument_type> { size_t operator()(argument_type const& x) const { size_t seed = random_seed; seed ^= hash<ll>{}(x.fi); seed ^= (hash<ll>{}(x.se) << 1); return seed; } }; }; // hash for various class
struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; }
struct init_{init_(){ ios::sync_with_stdio(false); cin.tie(0); gettimeofday(&start, NULL); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; }} init__;
#define ldout fixed << setprecision(40) 

#define EPS (double)1e-14
#define INF (ll)1e18
#define mo  (ll)(1e9+7)

// 根ノードを1としているので、
// 左の子:k*2
// 右の子:k*2+1
// 親:floor(k/2)
// となる。
// 根ノードを1とすると非再帰が書きやすい(二進数的性質が優れているため)のだが、
// 再帰的に書くのであればどちらでも問題ない。

const int N = 1 << 18;  // 葉の個数
const int NIL = INT_MAX;

int maxi[N * 2]; // ノードkに対応する区間の最大値
int lazy[N * 2]; // lazy[k]はノードkの配下全体をlazy[k]で塗りつぶすという命令を表す。lazy[k]=NILのときは何もしないと約束する

// 「頂点kを最新に更新する」を定義する。
// 
// 「頂点kの最大値データを正しい状態にする。
// でも、頂点kよりも子供側は、まだ正しい状態にしない。
// その代わり、頂点kの子供を最新の状態にするための情報lazyを持っておく。」

// 頂点kを最新の状態にする
void setLazy(int k, int v) {
    lazy[k] = v;

    // このノードの配下全体を v で塗りつぶす予定なのだから、当然、ノードkの最大値はvである
    maxi[k] = v;

    // *** 余談 ***
    // この発想が遅延セグメント木ではもっとも重要。
    // 命令がO(1)のメモリで表現でき、命令のマージが高速にできるのであれば遅延セグメント木で対処できる。
    // たとえば、区間加算と区間塗りつぶしの機能を両方備えたセグメント木を作るのであれば、
    // 
    // fill v := v で塗りつぶせ
    // add v := v を加算しろ
    //
    // という二種類の命令が必要になるだろう。
    // add u をした後に fill v をすることを (fill v) . (add u) と書くことにしよう。
    // このとき以下の関係式が成り立つ。
    // 
    // (add v) . (add u) = (add v+u)
    // (add v) . (fill u) = (fill v+u)
    // (fill v) . (add u) = (fill v)
    // (fill v) . (fill u) = (fill v)
    // 
    // つまり、add u と fill u 同士の演算は (add or fill, Int) で閉じている。
    // よって、命令は add であるか fill であるかという二値の情報と、加算/塗りつぶす値の 2 つの情報によって表現できる。
    // 複数の命令を、等価な単一の命令に置き換えられるか?、と考えると分かりやすいかもしれない。
    //
    // 遅延セグメント木はかならず時系列順にマージすることになる。
    // これが遅延伝搬セグメント木の最大の利点といえる。
    // 要するに、非可換の命令を扱うのに適している。
    // 
    // 誤解を生まないように一応書いておくが、塗りつぶしを遅延伝搬なしに書くことは不可能ではない。
    // 塗りつぶした時間も保持しておけば、
    //  (timeS, valueS) . (timeT, valueT) = max((timeS, valueS), (timeT, valueT))
    // として可換操作に変形できる。
}

// 頂点kの子供を最新の状態にする。
// push(x)すると、xのlazyがなくなる。
// 
// lazyがないならば、子供が最新である。
// 子を最新にし終えたので、lazyを解消する。
//
// lazyを持つ頂点の子供は全員、maxiが最新の状態に更新されていない。なので、maxiを見ても意味がない。
// 子供が正しい状態にするための情報は、親が握っている。
// なので、子供のmaxiにアクセスするためには、その頂点の親全てを上からpushしていかなければならない。
void push(int k/*node_id*/) {
    // 遅延命令がなにもなければ何もしない
    if (lazy[k] == NIL) {
        return;
    }
    // 子に伝播して
    setLazy(k * 2 + 0, lazy[k]);
    setLazy(k * 2 + 1, lazy[k]);
    
    // 子に命令を伝搬させたので、命令を空にする
    lazy[k] = NIL;
}

void fix(int k) {
    // ノードkに対応する区間の最大値は、「左の子の最大値」と「右の子の最大値」の最大値
    maxi[k] = max(maxi[k * 2], maxi[k * 2 + 1]);
}

// 区間[queryL,queryR)をvalで塗りつぶす
// kはノード番号で、[nodeL, nodeR)の区間を表す(本当は情報的にはkのみで良いが、簡便のためにnodeL, nodeRも関数に渡している)
void fill(int queryL, int queryR, int val, int k = 1 /*node_id*/, int nodeL = 0, int nodeR = N) {
//    cout << queryL << " " << queryR << " " << val << " " << k << " " << nodeL << " " << nodeR << endl;
    // クエリ区間とノード区間が交差していないなら、これ以上、処理する意味はない
    if (nodeR <= queryL || queryR <= nodeL) {
        return;
    }
    // ノード区間がクエリ区間に完全に覆われたら、遅延命令をセットして、さっさと帰る
    if (queryL <= nodeL && nodeR <= queryR) {
        setLazy(k, val);
        return;
    }
    // ノードが下がるときには命令をpushする
    push(k); // 子を最新の状態にしないと下がれないのでpush
    int nodeM = (nodeL + nodeR) / 2;
    fill(queryL, queryR, val, k * 2 + 0, nodeL, nodeM);
    fill(queryL, queryR, val, k * 2 + 1, nodeM, nodeR);

    // ノードが上がるときには情報をfixする
    fix(k);
}

// 区間[queryL, queryR)の最大値を求める
int maximum(int queryL, int queryR, int k = 1, int nodeL = 0, int nodeR = N) {
    // クエリ区間とノード区間が交差していない
    if (nodeR <= queryL || queryR <= nodeL) {
        return INT_MIN;
    }
    // ノード区間がクエリ区間に完全に覆われた
    if (queryL <= nodeL && nodeR <= queryR) {
        return maxi[k];
    }
    // ノードが下がるときには命令をpushする
    push(k); // 子を最新の状態にしないと下がれないのでpush
    int nodeM = (nodeL + nodeR) / 2;
    int vl = maximum(queryL, queryR, k * 2 + 0, nodeL, nodeM);
    int vr = maximum(queryL, queryR, k * 2 + 1, nodeM, nodeR);
    return max(vl, vr);
}

int main(void) {
    rep(i, N * 2) lazy[i] = NIL;
    fill(0, N * 2, -1);
    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));
        memo[{x, y, z}] = i;
    }
    vector<vll> ret;
    for (ll i = g.size() - 1; i >= 0; i--) {
        sort(all(g[i]));
        reverse(all(g[i]));
        vector<P> next;
        ll M = -1;
        for (auto x : g[i]) {
//            cout << i << " " << x  <<  " " << M << endl;
//            rep(i, 10) cout << maximum(i, i+1) << " "; cout << endl;
            if (x.se > M && x.se > maximum(x.fi, x.fi+1)) {
//                cout << "#HIT" << endl;
                chmax(M, x.se);
                next.pb(x);
                ret.pb({i, x.fi, x.se});
            }
        }
        for (auto x : next) {
            fill(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