#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, x, a[maxN];
int b[maxN];
int f[maxN], e[maxN];
int dp[maxN];
int st[4 * maxN];
void update(int id, int l, int r, int pos, int val)
{
if(l > pos || r < pos) return;
if(l == r && l == pos)
{
st[id] = val;
return;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, pos, val);
update(id * 2 + 1, mid + 1, r, pos, val);
st[id] = min(st[id * 2], st[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v)
{
if(l > v || r < u) return oo;
if(l >= u && r <= v) return st[id];
int mid = (l + r) / 2;
return min(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
void ReadInput()
{
cin >> n >> x;
for(int i=1; i<=n; i++) cin >> a[i];
}
void Solve()
{
for(int i=1; i<=n; i++) b[i] = -a[i];
memset(e, 3, sizeof e);
for(int i=n; i>=1; i--)
{
int j = lower_bound(e + 1, e + n + 1, b[i]) - e;
dp[i] = j;
e[dp[i]] = b[i];
}
memset(e, 3, sizeof e);
for(int i=1; i<=n; i++)
{
int j = lower_bound(e + 1, e + n + 1, a[i]) - e;
f[i] = j;
e[f[i]] = a[i];
}
memset(st, 3, sizeof st);
int res = 0;
for(int i=1; i<=n; i++)
{
int tmp = a[i] + x - 1;
int low = 1, high = n, mid;
while(low <= high)
{
mid = (low + high) / 2;
if(get(1, 1, n, mid, n) <= tmp) low = mid + 1;
else high = mid - 1;
}
res = max(res, dp[i] + high);
update(1, 1, n, f[i], a[i]);
}
cout << res << '\n';
}
int32_t main()
{
//freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
39380 KB |
Output is correct |
2 |
Correct |
20 ms |
39460 KB |
Output is correct |
3 |
Correct |
16 ms |
39428 KB |
Output is correct |
4 |
Correct |
16 ms |
39444 KB |
Output is correct |
5 |
Correct |
16 ms |
39472 KB |
Output is correct |
6 |
Correct |
20 ms |
39380 KB |
Output is correct |
7 |
Correct |
16 ms |
39380 KB |
Output is correct |
8 |
Correct |
19 ms |
39492 KB |
Output is correct |
9 |
Correct |
16 ms |
39380 KB |
Output is correct |
10 |
Correct |
17 ms |
39412 KB |
Output is correct |
11 |
Correct |
15 ms |
39380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
39380 KB |
Output is correct |
2 |
Correct |
20 ms |
39460 KB |
Output is correct |
3 |
Correct |
16 ms |
39428 KB |
Output is correct |
4 |
Correct |
16 ms |
39444 KB |
Output is correct |
5 |
Correct |
16 ms |
39472 KB |
Output is correct |
6 |
Correct |
20 ms |
39380 KB |
Output is correct |
7 |
Correct |
16 ms |
39380 KB |
Output is correct |
8 |
Correct |
19 ms |
39492 KB |
Output is correct |
9 |
Correct |
16 ms |
39380 KB |
Output is correct |
10 |
Correct |
17 ms |
39412 KB |
Output is correct |
11 |
Correct |
15 ms |
39380 KB |
Output is correct |
12 |
Correct |
16 ms |
39380 KB |
Output is correct |
13 |
Correct |
16 ms |
39380 KB |
Output is correct |
14 |
Correct |
16 ms |
39380 KB |
Output is correct |
15 |
Correct |
22 ms |
39472 KB |
Output is correct |
16 |
Correct |
19 ms |
39400 KB |
Output is correct |
17 |
Correct |
20 ms |
39380 KB |
Output is correct |
18 |
Correct |
17 ms |
39472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
39380 KB |
Output is correct |
2 |
Correct |
20 ms |
39460 KB |
Output is correct |
3 |
Correct |
16 ms |
39428 KB |
Output is correct |
4 |
Correct |
16 ms |
39444 KB |
Output is correct |
5 |
Correct |
16 ms |
39472 KB |
Output is correct |
6 |
Correct |
20 ms |
39380 KB |
Output is correct |
7 |
Correct |
16 ms |
39380 KB |
Output is correct |
8 |
Correct |
19 ms |
39492 KB |
Output is correct |
9 |
Correct |
16 ms |
39380 KB |
Output is correct |
10 |
Correct |
17 ms |
39412 KB |
Output is correct |
11 |
Correct |
15 ms |
39380 KB |
Output is correct |
12 |
Correct |
16 ms |
39380 KB |
Output is correct |
13 |
Correct |
16 ms |
39380 KB |
Output is correct |
14 |
Correct |
16 ms |
39380 KB |
Output is correct |
15 |
Correct |
22 ms |
39472 KB |
Output is correct |
16 |
Correct |
19 ms |
39400 KB |
Output is correct |
17 |
Correct |
20 ms |
39380 KB |
Output is correct |
18 |
Correct |
17 ms |
39472 KB |
Output is correct |
19 |
Correct |
17 ms |
39480 KB |
Output is correct |
20 |
Correct |
17 ms |
39404 KB |
Output is correct |
21 |
Correct |
17 ms |
39520 KB |
Output is correct |
22 |
Correct |
17 ms |
39408 KB |
Output is correct |
23 |
Correct |
18 ms |
39420 KB |
Output is correct |
24 |
Correct |
18 ms |
39504 KB |
Output is correct |
25 |
Correct |
22 ms |
39508 KB |
Output is correct |
26 |
Correct |
18 ms |
39508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
550 ms |
45740 KB |
Output is correct |
2 |
Correct |
530 ms |
47672 KB |
Output is correct |
3 |
Correct |
535 ms |
47672 KB |
Output is correct |
4 |
Correct |
520 ms |
47676 KB |
Output is correct |
5 |
Correct |
472 ms |
46908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
41044 KB |
Output is correct |
2 |
Correct |
123 ms |
41432 KB |
Output is correct |
3 |
Correct |
119 ms |
41524 KB |
Output is correct |
4 |
Correct |
127 ms |
41340 KB |
Output is correct |
5 |
Correct |
18 ms |
39380 KB |
Output is correct |
6 |
Correct |
110 ms |
41332 KB |
Output is correct |
7 |
Correct |
112 ms |
41532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
42612 KB |
Output is correct |
2 |
Correct |
242 ms |
43576 KB |
Output is correct |
3 |
Correct |
497 ms |
47676 KB |
Output is correct |
4 |
Correct |
471 ms |
46904 KB |
Output is correct |
5 |
Correct |
222 ms |
43180 KB |
Output is correct |
6 |
Correct |
475 ms |
46712 KB |
Output is correct |
7 |
Correct |
441 ms |
47292 KB |
Output is correct |
8 |
Correct |
232 ms |
43588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
39380 KB |
Output is correct |
2 |
Correct |
20 ms |
39460 KB |
Output is correct |
3 |
Correct |
16 ms |
39428 KB |
Output is correct |
4 |
Correct |
16 ms |
39444 KB |
Output is correct |
5 |
Correct |
16 ms |
39472 KB |
Output is correct |
6 |
Correct |
20 ms |
39380 KB |
Output is correct |
7 |
Correct |
16 ms |
39380 KB |
Output is correct |
8 |
Correct |
19 ms |
39492 KB |
Output is correct |
9 |
Correct |
16 ms |
39380 KB |
Output is correct |
10 |
Correct |
17 ms |
39412 KB |
Output is correct |
11 |
Correct |
15 ms |
39380 KB |
Output is correct |
12 |
Correct |
16 ms |
39380 KB |
Output is correct |
13 |
Correct |
16 ms |
39380 KB |
Output is correct |
14 |
Correct |
16 ms |
39380 KB |
Output is correct |
15 |
Correct |
22 ms |
39472 KB |
Output is correct |
16 |
Correct |
19 ms |
39400 KB |
Output is correct |
17 |
Correct |
20 ms |
39380 KB |
Output is correct |
18 |
Correct |
17 ms |
39472 KB |
Output is correct |
19 |
Correct |
17 ms |
39480 KB |
Output is correct |
20 |
Correct |
17 ms |
39404 KB |
Output is correct |
21 |
Correct |
17 ms |
39520 KB |
Output is correct |
22 |
Correct |
17 ms |
39408 KB |
Output is correct |
23 |
Correct |
18 ms |
39420 KB |
Output is correct |
24 |
Correct |
18 ms |
39504 KB |
Output is correct |
25 |
Correct |
22 ms |
39508 KB |
Output is correct |
26 |
Correct |
18 ms |
39508 KB |
Output is correct |
27 |
Correct |
550 ms |
45740 KB |
Output is correct |
28 |
Correct |
530 ms |
47672 KB |
Output is correct |
29 |
Correct |
535 ms |
47672 KB |
Output is correct |
30 |
Correct |
520 ms |
47676 KB |
Output is correct |
31 |
Correct |
472 ms |
46908 KB |
Output is correct |
32 |
Correct |
123 ms |
41044 KB |
Output is correct |
33 |
Correct |
123 ms |
41432 KB |
Output is correct |
34 |
Correct |
119 ms |
41524 KB |
Output is correct |
35 |
Correct |
127 ms |
41340 KB |
Output is correct |
36 |
Correct |
18 ms |
39380 KB |
Output is correct |
37 |
Correct |
110 ms |
41332 KB |
Output is correct |
38 |
Correct |
112 ms |
41532 KB |
Output is correct |
39 |
Correct |
238 ms |
42612 KB |
Output is correct |
40 |
Correct |
242 ms |
43576 KB |
Output is correct |
41 |
Correct |
497 ms |
47676 KB |
Output is correct |
42 |
Correct |
471 ms |
46904 KB |
Output is correct |
43 |
Correct |
222 ms |
43180 KB |
Output is correct |
44 |
Correct |
475 ms |
46712 KB |
Output is correct |
45 |
Correct |
441 ms |
47292 KB |
Output is correct |
46 |
Correct |
232 ms |
43588 KB |
Output is correct |
47 |
Correct |
252 ms |
43576 KB |
Output is correct |
48 |
Correct |
297 ms |
43612 KB |
Output is correct |
49 |
Correct |
503 ms |
47672 KB |
Output is correct |
50 |
Correct |
499 ms |
46844 KB |
Output is correct |
51 |
Correct |
352 ms |
45044 KB |
Output is correct |
52 |
Correct |
471 ms |
47012 KB |
Output is correct |
53 |
Correct |
475 ms |
47000 KB |
Output is correct |
54 |
Correct |
521 ms |
47704 KB |
Output is correct |
55 |
Correct |
493 ms |
47704 KB |
Output is correct |