結果

問題 No.777 再帰的ケーキ
ユーザー beetbeet
提出日時 2019-03-27 15:03:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 2,128 bytes
コンパイル時間 3,003 ms
コンパイル使用メモリ 222,604 KB
実行使用メモリ 27,712 KB
最終ジャッジ日時 2024-04-19 09:58:20
合計ジャッジ時間 7,303 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 357 ms
27,712 KB
testcase_29 AC 356 ms
27,700 KB
testcase_30 AC 373 ms
27,628 KB
testcase_31 AC 371 ms
27,624 KB
testcase_32 AC 236 ms
27,664 KB
testcase_33 AC 71 ms
12,708 KB
testcase_34 AC 105 ms
14,260 KB
testcase_35 AC 256 ms
18,484 KB
testcase_36 AC 233 ms
27,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  Int n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}
  void init(Int n_){    
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    Int n_=v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i]=v[i];
    for(Int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(Int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
  }
  T query(Int a,Int b){
    T vl=ti,vr=ti;
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n),b(n),c(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
  {
    using T = tuple<Int, Int, Int>;
    vector<T> vt;
    for(Int i=0;i<n;i++) vt.emplace_back(-a[i],b[i],c[i]);
    sort(vt.begin(),vt.end());
    for(Int i=0;i<n;i++) tie(a[i],b[i],c[i])=vt[i],a[i]=-a[i];    
  }
  vector<Int> vs(b);
  vs.emplace_back(0);
  vs.emplace_back(1e9+100);
  vs=compress(vs);
  auto dc=dict(vs);  
  
  auto f=[](Int a,Int b){return max(a,b);};
  SegmentTree<Int> seg(f,0);
  seg.build(vector<Int>(vs.size(),0));
  for(Int i=0;i<n;i++){
    Int k=dc[b[i]];
    Int v=seg.query(k+1,vs.size())+c[i];
    Int res=seg.query(k,k+1);
    if(res<v) seg.set_val(k,v);
  }
  cout<<seg.query(0,vs.size())<<endl;
  return 0;
}
0