結果

問題 No.992 最長増加部分列の数え上げ
ユーザー tko919tko919
提出日時 2020-03-05 12:15:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 2,973 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 173,368 KB
実行使用メモリ 7,128 KB
最終ジャッジ日時 2023-08-04 03:51:20
合計ジャッジ時間 8,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,112 KB
testcase_01 AC 2 ms
5,052 KB
testcase_02 AC 3 ms
5,244 KB
testcase_03 AC 3 ms
5,048 KB
testcase_04 AC 29 ms
5,536 KB
testcase_05 AC 22 ms
5,708 KB
testcase_06 AC 35 ms
5,688 KB
testcase_07 AC 27 ms
5,460 KB
testcase_08 AC 15 ms
5,416 KB
testcase_09 AC 28 ms
5,432 KB
testcase_10 AC 35 ms
5,740 KB
testcase_11 AC 44 ms
6,052 KB
testcase_12 AC 11 ms
5,268 KB
testcase_13 AC 25 ms
5,424 KB
testcase_14 AC 26 ms
5,412 KB
testcase_15 AC 11 ms
5,276 KB
testcase_16 AC 69 ms
6,864 KB
testcase_17 AC 15 ms
5,256 KB
testcase_18 AC 25 ms
5,516 KB
testcase_19 AC 44 ms
6,060 KB
testcase_20 AC 76 ms
7,048 KB
testcase_21 AC 77 ms
7,128 KB
testcase_22 AC 77 ms
6,940 KB
testcase_23 AC 76 ms
7,064 KB
testcase_24 AC 77 ms
7,056 KB
testcase_25 AC 76 ms
7,064 KB
testcase_26 AC 77 ms
7,120 KB
testcase_27 AC 76 ms
6,940 KB
testcase_28 AC 76 ms
7,008 KB
testcase_29 AC 76 ms
7,008 KB
testcase_30 AC 60 ms
7,004 KB
testcase_31 AC 60 ms
7,012 KB
testcase_32 AC 60 ms
7,060 KB
testcase_33 AC 59 ms
7,044 KB
testcase_34 AC 57 ms
7,124 KB
testcase_35 AC 64 ms
6,940 KB
testcase_36 AC 65 ms
6,944 KB
testcase_37 AC 64 ms
7,128 KB
testcase_38 AC 65 ms
7,000 KB
testcase_39 AC 65 ms
7,120 KB
testcase_40 AC 59 ms
7,120 KB
testcase_41 AC 60 ms
7,060 KB
testcase_42 AC 61 ms
7,120 KB
testcase_43 AC 60 ms
7,104 KB
testcase_44 AC 61 ms
7,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<unsigned mod=1000000007>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=1000000007>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
using Mint=mint<>;
typedef pair<int,int> P;
typedef pair<int,Mint> Q;
Q operator+(Q a,Q b){
   if(a.first>b.first)return a;
   else if(a.first<b.first)return b;
   else return Q{a.first,a.second+b.second};
}
int N; Q bit[201000];
void add(int i,Q x){
   for(i++;i<=N;i+=(i&-i))bit[i]=bit[i]+x;
}
Q sum(int i){
   Q res={0,0}; for(i++;i;i-=i&-i)res=res+bit[i]; return res;
}

int main(){
   int n; scanf("%d",&n);
   vector<int> a(n);
   rep(i,0,n)scanf("%d",&a[i]);
   vector<P> b(n);
   rep(i,0,n)b[i]={a[i],-i};
   sort(ALL(b));
   N=n+10; add(0,{0,1});
   rep(i,0,n){
      int pos=-b[i].second;
      Q x=sum(pos); x.first++;
      add(pos+1,x);
   }
   printf("%d\n",sum(n+1).second.val);
   return 0;
}
0