結果
| 問題 |
No.992 最長増加部分列の数え上げ
|
| コンテスト | |
| ユーザー |
heno239
|
| 提出日時 | 2020-02-15 03:15:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,167 bytes |
| コンパイル時間 | 1,542 ms |
| コンパイル使用メモリ | 131,120 KB |
| 実行使用メモリ | 22,436 KB |
| 最終ジャッジ日時 | 2024-10-06 13:38:28 |
| 合計ジャッジ時間 | 10,932 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 WA * 5 |
ソースコード
#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;
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;
}
heno239