結果

問題 No.992 最長増加部分列の数え上げ
ユーザー chocoruskchocorusk
提出日時 2020-02-15 04:56:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 1,337 ms
コンパイル使用メモリ 122,880 KB
実行使用メモリ 16,340 KB
最終ジャッジ日時 2024-04-16 03:06:27
合計ジャッジ時間 9,154 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,912 KB
testcase_01 AC 3 ms
6,912 KB
testcase_02 AC 3 ms
6,912 KB
testcase_03 AC 3 ms
6,656 KB
testcase_04 AC 77 ms
11,008 KB
testcase_05 AC 56 ms
8,960 KB
testcase_06 AC 96 ms
11,392 KB
testcase_07 AC 68 ms
11,056 KB
testcase_08 AC 38 ms
8,832 KB
testcase_09 AC 72 ms
11,136 KB
testcase_10 AC 94 ms
11,136 KB
testcase_11 AC 122 ms
11,648 KB
testcase_12 AC 26 ms
7,552 KB
testcase_13 AC 66 ms
11,136 KB
testcase_14 AC 67 ms
10,996 KB
testcase_15 AC 26 ms
7,596 KB
testcase_16 AC 188 ms
16,068 KB
testcase_17 AC 37 ms
8,636 KB
testcase_18 AC 64 ms
10,948 KB
testcase_19 AC 117 ms
11,460 KB
testcase_20 AC 206 ms
16,096 KB
testcase_21 AC 211 ms
16,072 KB
testcase_22 AC 214 ms
16,096 KB
testcase_23 AC 212 ms
16,256 KB
testcase_24 AC 214 ms
16,128 KB
testcase_25 AC 215 ms
16,072 KB
testcase_26 AC 213 ms
16,092 KB
testcase_27 AC 209 ms
16,128 KB
testcase_28 AC 210 ms
16,168 KB
testcase_29 AC 209 ms
16,312 KB
testcase_30 AC 185 ms
16,176 KB
testcase_31 AC 184 ms
16,156 KB
testcase_32 AC 186 ms
16,256 KB
testcase_33 AC 184 ms
16,176 KB
testcase_34 AC 183 ms
16,128 KB
testcase_35 AC 189 ms
16,092 KB
testcase_36 AC 189 ms
16,304 KB
testcase_37 AC 186 ms
16,256 KB
testcase_38 AC 185 ms
16,240 KB
testcase_39 AC 186 ms
16,076 KB
testcase_40 AC 178 ms
16,036 KB
testcase_41 AC 180 ms
16,128 KB
testcase_42 AC 181 ms
16,128 KB
testcase_43 AC 182 ms
16,340 KB
testcase_44 AC 182 ms
16,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
const ll MOD=1e9+7;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int main()
{
	int n; cin>>n;
	int a[200020];
	vector<int> va(n);
	for(int i=0; i<n; i++){
		cin>>a[i];
		va[i]=a[i];
	}
	sort(va.begin(), va.end());
	va.erase(unique(va.begin(), va.end()), va.end());
	int m=va.size()+1;
	for(int i=0; i<n; i++) a[i]=lower_bound(va.begin(), va.end(), a[i])-va.begin()+1;
	P dp[200020];
	dp[0]=P(0, 1);
	auto f=[](P a, P b){
		if(a.first!=b.first) return max(a, b);
		else return P(a.first, (a.second+b.second)%MOD);
	};
	SegmentTree<P> seg(m, f, P(-1, 0));
	seg.update(0, dp[0]);
	for(int i=0; i<n; i++){
		P p=seg.query(0, a[i]);
		dp[i+1]=P(p.first+1, p.second);
		seg.update(a[i], f(seg[a[i]], dp[i+1]));
	}
	P ans=seg.query(0, m);
	cout<<ans.second<<endl;
	return 0;
}
0