#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
const int MAX = 200010;
int n, x;
int arr[MAX][3];
int dp[MAX][3];
vi qu[3];
void modify(int i, int j, int k){
int pos = dp[i][j] - 1;
assert(pos <= szof(qu[k]));
if(pos == szof(qu[k])){
qu[k].pb(arr[i][j]);
}
else{
qu[k][pos] = min(qu[k][pos], arr[i][j]);
}
}
int query(int j, int T){
/// find max{dp[i][j]} s.t. arr[i] < T
if(qu[j].empty()){
return 0;
}
if(T <= qu[j][0]){
return 0;
}
int L = 0, R = szof(qu[j]) - 1, mid;
while(L < R){
mid = (L + R + 1) / 2;
if(T > qu[j][mid]){
L = mid;
}
else{
R = mid - 1;
}
}
/// qu[i] : dp = i + 1
return L + 1;
}
int solve(int d){
//cerr<<"solve("<<d<<") : "<<endl;
/// init
FOR(j, 0, 2, 1){
qu[j].clear();
}
FOR(i, 1, n, 1){
arr[i][1] = arr[i][0] + d;
}
/// dp
FOR(i, 1, n, 1){
FOR(j, 0, 2, 1){
dp[i][j] = query(j, arr[i][j]) + 1;
//cerr<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<"\t";
}
//cerr<<endl;
FOR(j, 0, 2, 1){
FOR(k, 0, j, 1){
modify(i, k, j);
}
/*
cerr<<"qu["<<j<<"] : ";
for(int i : qu[j]){
cerr<<i<<" ";
}
cerr<<endl;
*/
}
}
int ret = 0;
FOR(i, 1, n, 1){
FOR(j, 0, 2, 1){
ret = max(ret, dp[i][j]);
}
}
return ret;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>x;
FOR(i, 1, n, 1){
cin>>arr[i][0];
arr[i][2] = arr[i][0];
}
int res = 0;
FOR(d, -x, x, 1){
res = max(res, solve(d));
}
cout<<res<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Execution timed out |
2074 ms |
332 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
11540 KB |
Output is correct |
2 |
Correct |
66 ms |
11520 KB |
Output is correct |
3 |
Correct |
66 ms |
11408 KB |
Output is correct |
4 |
Correct |
66 ms |
11520 KB |
Output is correct |
5 |
Correct |
51 ms |
13096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
3168 KB |
Output is correct |
2 |
Correct |
96 ms |
3160 KB |
Output is correct |
3 |
Correct |
95 ms |
3152 KB |
Output is correct |
4 |
Correct |
70 ms |
3660 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
62 ms |
3672 KB |
Output is correct |
7 |
Correct |
69 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
5944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Execution timed out |
2074 ms |
332 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |