1 条题解
-
0

#include <bits/stdc++.h> using std::cin; using std::cout; const int N = 200054; int n; int a[N], D[N], f[N], g[N]; inline void up(int &x, const int y) {x < y ? x = y : 0;} void LIS(int *f) { int i, L = 0; for (i = 1; i <= n; ++i) f[i] = std::upper_bound(D + 1, D + (L + 1), i, [] (const int x, const int y) {return a[x] < a[y];}) - D, up(L, f[i]), D[f[i]] = i; } int main() { int i, x, ans = 0; std::ios::sync_with_stdio(false), cin.tie(NULL); cin >> n; for (i = 1; i <= n; ++i) cin >> x, a[x] = i; LIS(f); std::reverse(a + 1, a + (n + 1)); LIS(g); for (i = 1; i <= n; ++i) up(ans, f[i] + g[n - i + 1]); cout << --ans << '\n'; return 0; }
- 1
信息
- ID
- 5592
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者