結果

問題 No.992 最長増加部分列の数え上げ
ユーザー 👑 kmjpkmjp
提出日時 2020-02-15 00:19:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,648 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 165,376 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-16 03:02:44
合計ジャッジ時間 6,297 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 45 ms
6,400 KB
testcase_05 AC 33 ms
5,504 KB
testcase_06 AC 55 ms
7,040 KB
testcase_07 AC 40 ms
6,144 KB
testcase_08 AC 22 ms
5,376 KB
testcase_09 AC 41 ms
6,144 KB
testcase_10 AC 54 ms
6,912 KB
testcase_11 AC 68 ms
7,808 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 38 ms
5,888 KB
testcase_14 AC 39 ms
5,888 KB
testcase_15 AC 16 ms
5,376 KB
testcase_16 AC 103 ms
9,984 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 38 ms
6,016 KB
testcase_19 AC 67 ms
7,552 KB
testcase_20 AC 114 ms
10,624 KB
testcase_21 AC 113 ms
10,752 KB
testcase_22 AC 113 ms
10,752 KB
testcase_23 AC 115 ms
10,752 KB
testcase_24 AC 117 ms
10,624 KB
testcase_25 AC 114 ms
10,624 KB
testcase_26 AC 114 ms
10,752 KB
testcase_27 AC 115 ms
10,752 KB
testcase_28 AC 114 ms
10,624 KB
testcase_29 AC 115 ms
10,624 KB
testcase_30 AC 88 ms
10,496 KB
testcase_31 AC 89 ms
10,496 KB
testcase_32 AC 88 ms
10,752 KB
testcase_33 AC 89 ms
10,624 KB
testcase_34 AC 89 ms
10,624 KB
testcase_35 AC 84 ms
10,752 KB
testcase_36 AC 84 ms
10,624 KB
testcase_37 AC 83 ms
10,496 KB
testcase_38 AC 83 ms
10,752 KB
testcase_39 AC 84 ms
10,752 KB
testcase_40 AC 90 ms
10,752 KB
testcase_41 AC 88 ms
10,752 KB
testcase_42 AC 90 ms
10,496 KB
testcase_43 AC 90 ms
10,624 KB
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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]+1)-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