//============================================================================
// Name : I_love_cherry.cpp
// Author : mark
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int maxn = 211111;
int a[maxn];
int f[maxn], g[maxn], same[maxn];
void go(int dp[], int a[], int n, int same[]) {
vector<int> v;
for (int i = 0; i < n; ++i) {
int x = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
int y = upper_bound(v.begin(), v.end(), a[i]) - v.begin();
if (y == (int) v.size()) {
v.push_back(a[i]);
dp[i] = v.size();
} else {
v[y] = a[i];
dp[i] = y + 1;
}
same[i] = y - x + 1;
}
}
int main() {
int n, i;
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (i = 0; i < n; ++i)
scanf("%d", a + i);
reverse(a, a + n);
go(f, a, n, same);
for (i = 0; i < n; ++i)
a[i] *= -1;
go(g, a, n, same);
int ans = 0;
for (i = 0; i < n; ++i) {
ans = max(ans, f[i] + g[i] - same[i]);
}
printf("%d\n", ans);
}
return 0;
}
HDU 4604
最新推荐文章于 2019-10-01 10:52:24 发布