#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 = max(solve(x), solve(-x));
cout<<res<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
11588 KB |
Output is correct |
2 |
Correct |
101 ms |
11588 KB |
Output is correct |
3 |
Correct |
103 ms |
11560 KB |
Output is correct |
4 |
Correct |
101 ms |
11588 KB |
Output is correct |
5 |
Correct |
70 ms |
13228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3180 KB |
Output is correct |
2 |
Correct |
24 ms |
3068 KB |
Output is correct |
3 |
Correct |
24 ms |
3172 KB |
Output is correct |
4 |
Correct |
18 ms |
3700 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
15 ms |
3684 KB |
Output is correct |
7 |
Correct |
19 ms |
3136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
5968 KB |
Output is correct |
2 |
Correct |
56 ms |
5948 KB |
Output is correct |
3 |
Correct |
114 ms |
11664 KB |
Output is correct |
4 |
Correct |
72 ms |
13356 KB |
Output is correct |
5 |
Correct |
32 ms |
6888 KB |
Output is correct |
6 |
Correct |
61 ms |
12728 KB |
Output is correct |
7 |
Correct |
57 ms |
13348 KB |
Output is correct |
8 |
Correct |
41 ms |
5964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
100 ms |
11588 KB |
Output is correct |
28 |
Correct |
101 ms |
11588 KB |
Output is correct |
29 |
Correct |
103 ms |
11560 KB |
Output is correct |
30 |
Correct |
101 ms |
11588 KB |
Output is correct |
31 |
Correct |
70 ms |
13228 KB |
Output is correct |
32 |
Correct |
24 ms |
3180 KB |
Output is correct |
33 |
Correct |
24 ms |
3068 KB |
Output is correct |
34 |
Correct |
24 ms |
3172 KB |
Output is correct |
35 |
Correct |
18 ms |
3700 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
15 ms |
3684 KB |
Output is correct |
38 |
Correct |
19 ms |
3136 KB |
Output is correct |
39 |
Correct |
54 ms |
5968 KB |
Output is correct |
40 |
Correct |
56 ms |
5948 KB |
Output is correct |
41 |
Correct |
114 ms |
11664 KB |
Output is correct |
42 |
Correct |
72 ms |
13356 KB |
Output is correct |
43 |
Correct |
32 ms |
6888 KB |
Output is correct |
44 |
Correct |
61 ms |
12728 KB |
Output is correct |
45 |
Correct |
57 ms |
13348 KB |
Output is correct |
46 |
Correct |
41 ms |
5964 KB |
Output is correct |
47 |
Correct |
50 ms |
5996 KB |
Output is correct |
48 |
Correct |
48 ms |
5948 KB |
Output is correct |
49 |
Correct |
108 ms |
11628 KB |
Output is correct |
50 |
Correct |
75 ms |
13484 KB |
Output is correct |
51 |
Correct |
60 ms |
12324 KB |
Output is correct |
52 |
Correct |
68 ms |
13388 KB |
Output is correct |
53 |
Correct |
56 ms |
13356 KB |
Output is correct |
54 |
Correct |
58 ms |
14044 KB |
Output is correct |
55 |
Correct |
81 ms |
11600 KB |
Output is correct |