#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define FOR(i, u, v) for (int i = u; i <= v; i++)
#define FORD(i, v, u) for (int i = v; i >= u; i--)
#define N 200005
#define maxc 1ll*100000000000000007
#define ll long long
using namespace std;
int n, d, a[N], b[N], rr[N*2], cur, rig[N];
struct BIT
{
int t[N*2];
void reset()
{
memset(t, 0, sizeof t);
}
void upd(int x, int val)
{
for (; x < N*2; x += (x & -x)) t[x] = max(t[x], val);
}
int get(int x)
{
int ans = 0;
for (; x; x -= (x & -x)) ans = max(ans, t[x]);
return ans;
}
}t;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
cin >> n >> d;
FOR(i, 1, n)
{
cin >> a[i];
rr[++cur] = a[i];
rr[++cur] = a[i] + d;
}
sort(rr+1, rr+cur+1);
cur = unique(rr+1, rr+cur+1) - rr - 1;
FOR(i, 1, n)
{
b[i] = lower_bound(rr+1, rr+cur+1, a[i]+d) - rr;
a[i] = lower_bound(rr+1, rr+cur+1, a[i]) - rr;
}
FORD(i, n, 1)
{
rig[i] = t.get(cur - b[i]) + 1;
t.upd(cur - b[i] + 1, rig[i]);
}
int res = rig[1];
t.reset();
FOR(i, 1, n)
{
res = max(res, t.get(b[i]-1) + rig[i]);
int valLIS = t.get(a[i]-1) + 1;
t.upd(a[i], valLIS);
}
cout <<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1916 KB |
Output is correct |
3 |
Correct |
0 ms |
1976 KB |
Output is correct |
4 |
Correct |
4 ms |
1976 KB |
Output is correct |
5 |
Correct |
3 ms |
2164 KB |
Output is correct |
6 |
Correct |
3 ms |
2164 KB |
Output is correct |
7 |
Correct |
3 ms |
2164 KB |
Output is correct |
8 |
Correct |
3 ms |
2164 KB |
Output is correct |
9 |
Correct |
3 ms |
2164 KB |
Output is correct |
10 |
Correct |
3 ms |
2164 KB |
Output is correct |
11 |
Correct |
3 ms |
2164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1916 KB |
Output is correct |
3 |
Correct |
0 ms |
1976 KB |
Output is correct |
4 |
Correct |
4 ms |
1976 KB |
Output is correct |
5 |
Correct |
3 ms |
2164 KB |
Output is correct |
6 |
Correct |
3 ms |
2164 KB |
Output is correct |
7 |
Correct |
3 ms |
2164 KB |
Output is correct |
8 |
Correct |
3 ms |
2164 KB |
Output is correct |
9 |
Correct |
3 ms |
2164 KB |
Output is correct |
10 |
Correct |
3 ms |
2164 KB |
Output is correct |
11 |
Correct |
3 ms |
2164 KB |
Output is correct |
12 |
Correct |
3 ms |
2164 KB |
Output is correct |
13 |
Correct |
3 ms |
2164 KB |
Output is correct |
14 |
Correct |
3 ms |
2164 KB |
Output is correct |
15 |
Correct |
3 ms |
2164 KB |
Output is correct |
16 |
Correct |
3 ms |
2164 KB |
Output is correct |
17 |
Correct |
4 ms |
2164 KB |
Output is correct |
18 |
Correct |
3 ms |
2164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1916 KB |
Output is correct |
3 |
Correct |
0 ms |
1976 KB |
Output is correct |
4 |
Correct |
4 ms |
1976 KB |
Output is correct |
5 |
Correct |
3 ms |
2164 KB |
Output is correct |
6 |
Correct |
3 ms |
2164 KB |
Output is correct |
7 |
Correct |
3 ms |
2164 KB |
Output is correct |
8 |
Correct |
3 ms |
2164 KB |
Output is correct |
9 |
Correct |
3 ms |
2164 KB |
Output is correct |
10 |
Correct |
3 ms |
2164 KB |
Output is correct |
11 |
Correct |
3 ms |
2164 KB |
Output is correct |
12 |
Correct |
3 ms |
2164 KB |
Output is correct |
13 |
Correct |
3 ms |
2164 KB |
Output is correct |
14 |
Correct |
3 ms |
2164 KB |
Output is correct |
15 |
Correct |
3 ms |
2164 KB |
Output is correct |
16 |
Correct |
3 ms |
2164 KB |
Output is correct |
17 |
Correct |
4 ms |
2164 KB |
Output is correct |
18 |
Correct |
3 ms |
2164 KB |
Output is correct |
19 |
Correct |
4 ms |
2164 KB |
Output is correct |
20 |
Correct |
4 ms |
2164 KB |
Output is correct |
21 |
Correct |
4 ms |
2184 KB |
Output is correct |
22 |
Correct |
4 ms |
2184 KB |
Output is correct |
23 |
Correct |
4 ms |
2184 KB |
Output is correct |
24 |
Correct |
4 ms |
2184 KB |
Output is correct |
25 |
Correct |
4 ms |
2184 KB |
Output is correct |
26 |
Correct |
4 ms |
2184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
6100 KB |
Output is correct |
2 |
Correct |
160 ms |
6100 KB |
Output is correct |
3 |
Correct |
157 ms |
6232 KB |
Output is correct |
4 |
Correct |
152 ms |
6232 KB |
Output is correct |
5 |
Correct |
80 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
6232 KB |
Output is correct |
2 |
Correct |
39 ms |
6232 KB |
Output is correct |
3 |
Correct |
39 ms |
6232 KB |
Output is correct |
4 |
Correct |
23 ms |
6232 KB |
Output is correct |
5 |
Correct |
3 ms |
6232 KB |
Output is correct |
6 |
Correct |
20 ms |
6232 KB |
Output is correct |
7 |
Correct |
31 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
6232 KB |
Output is correct |
2 |
Correct |
79 ms |
6232 KB |
Output is correct |
3 |
Correct |
205 ms |
6232 KB |
Output is correct |
4 |
Correct |
92 ms |
6232 KB |
Output is correct |
5 |
Correct |
50 ms |
6232 KB |
Output is correct |
6 |
Correct |
84 ms |
6232 KB |
Output is correct |
7 |
Correct |
88 ms |
6232 KB |
Output is correct |
8 |
Correct |
63 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1916 KB |
Output is correct |
3 |
Correct |
0 ms |
1976 KB |
Output is correct |
4 |
Correct |
4 ms |
1976 KB |
Output is correct |
5 |
Correct |
3 ms |
2164 KB |
Output is correct |
6 |
Correct |
3 ms |
2164 KB |
Output is correct |
7 |
Correct |
3 ms |
2164 KB |
Output is correct |
8 |
Correct |
3 ms |
2164 KB |
Output is correct |
9 |
Correct |
3 ms |
2164 KB |
Output is correct |
10 |
Correct |
3 ms |
2164 KB |
Output is correct |
11 |
Correct |
3 ms |
2164 KB |
Output is correct |
12 |
Correct |
3 ms |
2164 KB |
Output is correct |
13 |
Correct |
3 ms |
2164 KB |
Output is correct |
14 |
Correct |
3 ms |
2164 KB |
Output is correct |
15 |
Correct |
3 ms |
2164 KB |
Output is correct |
16 |
Correct |
3 ms |
2164 KB |
Output is correct |
17 |
Correct |
4 ms |
2164 KB |
Output is correct |
18 |
Correct |
3 ms |
2164 KB |
Output is correct |
19 |
Correct |
4 ms |
2164 KB |
Output is correct |
20 |
Correct |
4 ms |
2164 KB |
Output is correct |
21 |
Correct |
4 ms |
2184 KB |
Output is correct |
22 |
Correct |
4 ms |
2184 KB |
Output is correct |
23 |
Correct |
4 ms |
2184 KB |
Output is correct |
24 |
Correct |
4 ms |
2184 KB |
Output is correct |
25 |
Correct |
4 ms |
2184 KB |
Output is correct |
26 |
Correct |
4 ms |
2184 KB |
Output is correct |
27 |
Correct |
150 ms |
6100 KB |
Output is correct |
28 |
Correct |
160 ms |
6100 KB |
Output is correct |
29 |
Correct |
157 ms |
6232 KB |
Output is correct |
30 |
Correct |
152 ms |
6232 KB |
Output is correct |
31 |
Correct |
80 ms |
6232 KB |
Output is correct |
32 |
Correct |
39 ms |
6232 KB |
Output is correct |
33 |
Correct |
39 ms |
6232 KB |
Output is correct |
34 |
Correct |
39 ms |
6232 KB |
Output is correct |
35 |
Correct |
23 ms |
6232 KB |
Output is correct |
36 |
Correct |
3 ms |
6232 KB |
Output is correct |
37 |
Correct |
20 ms |
6232 KB |
Output is correct |
38 |
Correct |
31 ms |
6232 KB |
Output is correct |
39 |
Correct |
78 ms |
6232 KB |
Output is correct |
40 |
Correct |
79 ms |
6232 KB |
Output is correct |
41 |
Correct |
205 ms |
6232 KB |
Output is correct |
42 |
Correct |
92 ms |
6232 KB |
Output is correct |
43 |
Correct |
50 ms |
6232 KB |
Output is correct |
44 |
Correct |
84 ms |
6232 KB |
Output is correct |
45 |
Correct |
88 ms |
6232 KB |
Output is correct |
46 |
Correct |
63 ms |
6232 KB |
Output is correct |
47 |
Correct |
75 ms |
6232 KB |
Output is correct |
48 |
Correct |
79 ms |
6232 KB |
Output is correct |
49 |
Correct |
162 ms |
6232 KB |
Output is correct |
50 |
Correct |
81 ms |
7332 KB |
Output is correct |
51 |
Correct |
63 ms |
7332 KB |
Output is correct |
52 |
Correct |
89 ms |
9416 KB |
Output is correct |
53 |
Correct |
86 ms |
10624 KB |
Output is correct |
54 |
Correct |
102 ms |
12652 KB |
Output is correct |
55 |
Correct |
139 ms |
14668 KB |
Output is correct |