結果

問題 No.127 門松もどき
ユーザー beetbeet
提出日時 2019-03-30 20:46:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,838 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 213,572 KB
実行使用メモリ 101,772 KB
最終ジャッジ日時 2023-08-10 18:59:44
合計ジャッジ時間 24,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,436 KB
testcase_01 AC 3 ms
5,364 KB
testcase_02 AC 3 ms
5,420 KB
testcase_03 AC 4 ms
5,388 KB
testcase_04 AC 2,118 ms
101,772 KB
testcase_05 AC 3 ms
5,264 KB
testcase_06 AC 95 ms
12,360 KB
testcase_07 AC 4 ms
5,320 KB
testcase_08 AC 4 ms
5,408 KB
testcase_09 AC 3 ms
5,300 KB
testcase_10 AC 4 ms
5,328 KB
testcase_11 AC 5 ms
5,636 KB
testcase_12 AC 1,016 ms
75,180 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,682 ms
96,564 KB
testcase_16 AC 1,183 ms
81,436 KB
testcase_17 AC 1,182 ms
87,252 KB
testcase_18 WA -
testcase_19 AC 523 ms
34,796 KB
testcase_20 AC 522 ms
35,004 KB
testcase_21 WA -
testcase_22 AC 2,003 ms
101,624 KB
testcase_23 AC 1,785 ms
101,760 KB
testcase_24 AC 1,558 ms
89,736 KB
testcase_25 AC 1,856 ms
97,180 KB
testcase_26 AC 804 ms
37,532 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);
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];

  auto f=[](int a,int b){return max(a,b);};

  vector< SegmentTree<int> > vs;
  for(int i=0;i<n;i++){
    vs.emplace_back(f,0);
    vs.back().build(vector<int>(n+1,0));
  }
  
  const int MAX = 1e5+100;
  vector<vector<int> > G(MAX);
  for(int i=0;i<n;i++) G[a[i]].emplace_back(i);

  int ans=1;
  for(int t=MAX-1;t>0;t--){
    if(G[t].empty()) continue;
    vector<vector<int> > nvs;
    for(int k:G[t]){
      vector<int> nv(n+1,0);
      for(int i=0;i<k;i++)
        nv[i]=vs[i].query(i,k)+1;
      for(int i=k+1;i<n;i++)
        nv[i]=vs[i].query(k,i)+1;

      chmax(ans,*max_element(nv.begin(),nv.end()));
      nvs.emplace_back(nv);
    }
    
    for(int i=0;i<(int)G[t].size();i++)
      vs[G[t][i]].build(nvs[i]);
  }

  cout<<ans<<endl;
  return 0;
}
0