結果

問題 No.992 最長増加部分列の数え上げ
ユーザー heno239heno239
提出日時 2020-02-15 03:16:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 129,336 KB
実行使用メモリ 22,512 KB
最終ジャッジ日時 2024-04-16 03:05:23
合計ジャッジ時間 11,178 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
5,376 KB
testcase_04 AC 105 ms
11,672 KB
testcase_05 AC 71 ms
8,448 KB
testcase_06 AC 134 ms
12,504 KB
testcase_07 AC 92 ms
11,124 KB
testcase_08 AC 41 ms
7,296 KB
testcase_09 AC 95 ms
11,388 KB
testcase_10 AC 136 ms
12,384 KB
testcase_11 AC 174 ms
13,884 KB
testcase_12 AC 26 ms
5,504 KB
testcase_13 AC 86 ms
10,988 KB
testcase_14 AC 86 ms
10,984 KB
testcase_15 AC 26 ms
5,632 KB
testcase_16 AC 296 ms
21,548 KB
testcase_17 AC 42 ms
7,296 KB
testcase_18 AC 87 ms
11,108 KB
testcase_19 AC 178 ms
13,748 KB
testcase_20 AC 342 ms
22,512 KB
testcase_21 AC 344 ms
22,388 KB
testcase_22 AC 339 ms
22,264 KB
testcase_23 AC 341 ms
22,388 KB
testcase_24 AC 345 ms
22,388 KB
testcase_25 AC 335 ms
22,388 KB
testcase_26 AC 334 ms
22,256 KB
testcase_27 AC 339 ms
22,340 KB
testcase_28 AC 340 ms
22,256 KB
testcase_29 AC 338 ms
22,388 KB
testcase_30 AC 187 ms
21,364 KB
testcase_31 AC 184 ms
21,492 KB
testcase_32 AC 188 ms
21,496 KB
testcase_33 AC 186 ms
21,620 KB
testcase_34 AC 187 ms
21,492 KB
testcase_35 AC 181 ms
21,492 KB
testcase_36 AC 181 ms
21,492 KB
testcase_37 AC 182 ms
21,492 KB
testcase_38 AC 182 ms
21,496 KB
testcase_39 AC 180 ms
21,368 KB
testcase_40 AC 188 ms
21,488 KB
testcase_41 AC 188 ms
21,368 KB
testcase_42 AC 188 ms
21,364 KB
testcase_43 AC 189 ms
21,492 KB
testcase_44 AC 192 ms
21,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<cassert>
#include<random>
#include<unordered_map>
#include<numeric>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

using P = pair<int, int>;
using LP = pair<ll, ll>;

struct SegT {
private:
	int sz; vector<LP> node;
	const LP init_c = { 0,0 };
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	LP f(LP a, LP b) {
		if (a.first < b.first)return b;
		if (a.first > b.first)return a;
		ll res = a.second + b.second;
		if (res >= mod)res -= mod;
		return { a.first,res };
	}
	void update(int k, LP a) {
		k += sz - 1;
		if (node[k].first == a.first) {
			node[k].second += a.second;
			if (node[k].second >= mod)node[k].second -= mod;
		}
		else if (node[k].first<a.first)node[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	LP query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			LP vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			LP vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<int> x;
	rep(i, n)x.push_back(a[i]);
	x.push_back(-mod);
	sort(all(x));
	x.erase(unique(all(x)), x.end());
	map<int, int> mp;
	rep(i, x.size())mp[x[i]] = i;
	rep(i, n)a[i] = mp[a[i]];

	SegT st(x.size());
	st.update(0,{ 0,1 });
	rep(i, n) {
		LP p = st.query(0, a[i]);
		p.first++;
		st.update(a[i], p);
	}
	LP ans = st.query(0, x.size());
	cout << ans.second << endl;

}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int t; cin >> t;rep(i,t) solve();
	solve();
	stop
		return 0;
}
0