/* IN THE NAME OF GOD */
/* |\/| /-\ |\| | |\/| /-\ */
#include "bits/stdc++.h"
using namespace std;
#define sz(x) (int)x.size()
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define mr make_pair
//#define int long long
#define pii pair<int, int>
typedef long double ld;
typedef long long ll;
mt19937 rng (chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 4e5 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9 + 1;
int a[N], fen[N], l[N], r[N];
vector<int> vec, dp;
void upd(int p, int x){
for(; p < N; p += p & -p)
fen[p] = max(fen[p], x);
}
int get(int p){
int ret = 0;
for(; p > 0; p -= p & -p)
ret = max(ret, fen[p]);
return ret;
}
int f(int x){
return lower_bound(all(vec), x) - vec.begin() + 1;
}
int32_t main(){
ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, x;
cin >> n >> x;
for(int i = 1; i <= n; i++){
cin >> a[i];
vec.pb(a[i]);
vec.pb(a[i] + x);
}
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
for(int i = 1; i <= n; i++){
int t = lower_bound(all(dp), a[i]) - dp.begin();
l[i] = t + 1;
if(t < sz(dp))
dp[t] = a[i];
else
dp.pb(a[i]);
}
reverse(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
a[i] *= -1;
dp.clear();
for(int i = 1; i <= n; i++){
int t = lower_bound(all(dp), a[i]) - dp.begin();
r[n - i + 1] = t + 1;
if(t < sz(dp))
dp[t] = a[i];
else
dp.pb(a[i]);
}
reverse(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
a[i] *= -1;
int ans = 0;
for(int i = 1; i <= n; i++){
ans = max(ans, r[i] + get(f(a[i] + x) - 1));
upd(f(a[i]), l[i]);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
456 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
456 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
7032 KB |
Output is correct |
2 |
Correct |
124 ms |
6988 KB |
Output is correct |
3 |
Correct |
125 ms |
7044 KB |
Output is correct |
4 |
Correct |
124 ms |
7064 KB |
Output is correct |
5 |
Correct |
56 ms |
6660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2296 KB |
Output is correct |
2 |
Correct |
31 ms |
2324 KB |
Output is correct |
3 |
Correct |
29 ms |
2312 KB |
Output is correct |
4 |
Correct |
15 ms |
2036 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
14 ms |
2020 KB |
Output is correct |
7 |
Correct |
25 ms |
2232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
3788 KB |
Output is correct |
2 |
Correct |
64 ms |
3752 KB |
Output is correct |
3 |
Correct |
130 ms |
6988 KB |
Output is correct |
4 |
Correct |
63 ms |
6668 KB |
Output is correct |
5 |
Correct |
41 ms |
3624 KB |
Output is correct |
6 |
Correct |
54 ms |
6860 KB |
Output is correct |
7 |
Correct |
64 ms |
7488 KB |
Output is correct |
8 |
Correct |
51 ms |
3768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
456 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
121 ms |
7032 KB |
Output is correct |
28 |
Correct |
124 ms |
6988 KB |
Output is correct |
29 |
Correct |
125 ms |
7044 KB |
Output is correct |
30 |
Correct |
124 ms |
7064 KB |
Output is correct |
31 |
Correct |
56 ms |
6660 KB |
Output is correct |
32 |
Correct |
31 ms |
2296 KB |
Output is correct |
33 |
Correct |
31 ms |
2324 KB |
Output is correct |
34 |
Correct |
29 ms |
2312 KB |
Output is correct |
35 |
Correct |
15 ms |
2036 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
14 ms |
2020 KB |
Output is correct |
38 |
Correct |
25 ms |
2232 KB |
Output is correct |
39 |
Correct |
64 ms |
3788 KB |
Output is correct |
40 |
Correct |
64 ms |
3752 KB |
Output is correct |
41 |
Correct |
130 ms |
6988 KB |
Output is correct |
42 |
Correct |
63 ms |
6668 KB |
Output is correct |
43 |
Correct |
41 ms |
3624 KB |
Output is correct |
44 |
Correct |
54 ms |
6860 KB |
Output is correct |
45 |
Correct |
64 ms |
7488 KB |
Output is correct |
46 |
Correct |
51 ms |
3768 KB |
Output is correct |
47 |
Correct |
59 ms |
4172 KB |
Output is correct |
48 |
Correct |
62 ms |
4160 KB |
Output is correct |
49 |
Correct |
127 ms |
7808 KB |
Output is correct |
50 |
Correct |
59 ms |
7068 KB |
Output is correct |
51 |
Correct |
50 ms |
5364 KB |
Output is correct |
52 |
Correct |
66 ms |
7180 KB |
Output is correct |
53 |
Correct |
58 ms |
7100 KB |
Output is correct |
54 |
Correct |
61 ms |
7844 KB |
Output is correct |
55 |
Correct |
102 ms |
7648 KB |
Output is correct |