結果

問題 No.992 最長増加部分列の数え上げ
ユーザー msm1993msm1993
提出日時 2020-04-02 17:02:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,646 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 165,912 KB
実行使用メモリ 10,760 KB
最終ジャッジ日時 2023-09-11 00:31:50
合計ジャッジ時間 9,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,676 KB
testcase_01 AC 3 ms
7,576 KB
testcase_02 AC 3 ms
7,540 KB
testcase_03 AC 3 ms
7,544 KB
testcase_04 AC 42 ms
8,580 KB
testcase_05 AC 31 ms
8,344 KB
testcase_06 AC 51 ms
8,812 KB
testcase_07 AC 37 ms
8,632 KB
testcase_08 AC 21 ms
8,252 KB
testcase_09 AC 38 ms
8,620 KB
testcase_10 AC 50 ms
8,808 KB
testcase_11 AC 63 ms
9,076 KB
testcase_12 AC 15 ms
7,996 KB
testcase_13 AC 36 ms
8,488 KB
testcase_14 AC 36 ms
8,496 KB
testcase_15 AC 16 ms
7,904 KB
testcase_16 AC 96 ms
10,020 KB
testcase_17 AC 22 ms
8,200 KB
testcase_18 AC 36 ms
8,424 KB
testcase_19 AC 63 ms
9,028 KB
testcase_20 AC 106 ms
10,528 KB
testcase_21 AC 106 ms
10,588 KB
testcase_22 AC 106 ms
10,568 KB
testcase_23 AC 106 ms
10,540 KB
testcase_24 AC 105 ms
10,640 KB
testcase_25 AC 106 ms
10,472 KB
testcase_26 AC 106 ms
10,592 KB
testcase_27 AC 108 ms
10,472 KB
testcase_28 AC 106 ms
10,500 KB
testcase_29 AC 106 ms
10,532 KB
testcase_30 AC 79 ms
10,528 KB
testcase_31 AC 79 ms
10,580 KB
testcase_32 AC 80 ms
10,696 KB
testcase_33 AC 80 ms
10,752 KB
testcase_34 AC 80 ms
10,760 KB
testcase_35 AC 77 ms
10,500 KB
testcase_36 AC 77 ms
10,548 KB
testcase_37 AC 77 ms
10,472 KB
testcase_38 AC 77 ms
10,576 KB
testcase_39 AC 77 ms
10,752 KB
testcase_40 AC 82 ms
10,644 KB
testcase_41 AC 82 ms
10,492 KB
testcase_42 AC 81 ms
10,548 KB
testcase_43 AC 82 ms
10,468 KB
testcase_44 AC 81 ms
10,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020],B[202020];
int ID[202020],IDnum[202020],IDs[202020];
int num[202020];
ll dp[202020];
int V[202020];
ll mo=1000000007;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s%mo;}
	void add(int e,V v) { e++; while(e<=1<<ME) (bit[e-1]+=v)%=mo,e+=e&-e;}
};
BIT<ll,20> bt;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	V[0]=-1<<30;
	FOR(i,N) V[i+1]=1<<30;
	int ma=0;
	FOR(i,N) {
		cin>>A[i];
		x=lower_bound(V,V+N+1,A[i])-V;
		ID[i]=x;
		ma=max(ma,x);
		IDnum[i]=++num[x];
		V[x]=A[i];
	}
	IDs[1]=1;
	for(i=2;i<=ma;i++) IDs[i]=IDs[i-1]+num[i-1];
	B[0]=-1<<30;
	FOR(i,N) B[IDs[ID[i]]+num[ID[i]]-IDnum[i]]=A[i];
	ll ret=0;
	bt.add(0,1);
	FOR(i,N) {
		x=lower_bound(B+IDs[ID[i]-1],B+IDs[ID[i]],A[i])-B;
		x--;
		dp[i]=(bt(x)-bt(IDs[ID[i]-1]-1)+mo)%mo;
		if(ID[i]==ma) ret+=dp[i];
		bt.add(IDs[ID[i]]+num[ID[i]]-IDnum[i],dp[i]);
	}
	cout<<ret%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0