#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int v[maxn], bit[2*maxn][2], sz_lds[maxn];
vector<int> ids;
void upd(int x, int val, int t){
for(; x < 2*maxn; x+=x&-x) {bit[x][t] = max(bit[x][t], val);}
}
int mx(int x, int t){
int rt = 0;
for(; x>0; x-=x&-x) rt = max(rt, bit[x][t]);
return rt;
}
int bbin(int x){
int l = 0, r = ids.size()-1, rt=0;
while(l<=r){
int mid = (l+r)>>1;
if(ids[mid] >= x) rt=mid, r = mid-1;
else l = mid+1;
}
return rt+1;
}
int main(){
int n, x; cin >> n >> x;
for(int i = 0; i < n; i++){
cin >> v[i];
ids.push_back(v[i]);
ids.push_back(v[i]+x);
}
sort(ids.begin(), ids.end());
ids.erase(unique(ids.begin(), ids.end()), ids.end());
// todas as coordenadas que importam estão comprimidas. Para acessar
// a coordenada comprimida use "bbin(val)" e ela retornará o id relativo (comprimido)
// 0-indexado + 1
int ans = 1;
reverse(v, v+n);
for(int i = 0; i < n; i++){
int id = bbin(v[i]+x);
id = 2*n+2-id;
sz_lds[n-1-i] = mx(id-1, 1)+1;// lds usando sufixo {n-1,n-2,..., n-1 - i}, v[i] incluso
upd(id, sz_lds[n-1-i], 1);
}
reverse(v, v+n);
for(int i = 0; i < n; i++){
int id_calc = bbin(v[i]+x);// id do limite da lis
int sz_lis_calc = mx(id_calc-1, 0);
ans = max(ans, sz_lis_calc + sz_lds[i]);
int id = bbin(v[i]);
int sz_lis = mx(id-1, 0)+1;
upd(id, sz_lis, 0);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
320 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
304 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
207 ms |
6624 KB |
Output is correct |
2 |
Correct |
218 ms |
8544 KB |
Output is correct |
3 |
Correct |
222 ms |
8548 KB |
Output is correct |
4 |
Correct |
203 ms |
8504 KB |
Output is correct |
5 |
Correct |
104 ms |
6212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
2008 KB |
Output is correct |
2 |
Correct |
51 ms |
2484 KB |
Output is correct |
3 |
Correct |
48 ms |
2508 KB |
Output is correct |
4 |
Correct |
29 ms |
2244 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
27 ms |
2204 KB |
Output is correct |
7 |
Correct |
53 ms |
2456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
2756 KB |
Output is correct |
2 |
Correct |
115 ms |
3660 KB |
Output is correct |
3 |
Correct |
235 ms |
6968 KB |
Output is correct |
4 |
Correct |
117 ms |
6288 KB |
Output is correct |
5 |
Correct |
65 ms |
3392 KB |
Output is correct |
6 |
Correct |
139 ms |
6080 KB |
Output is correct |
7 |
Correct |
141 ms |
6620 KB |
Output is correct |
8 |
Correct |
92 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
320 KB |
Output is correct |
23 |
Correct |
1 ms |
304 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
304 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
207 ms |
6624 KB |
Output is correct |
28 |
Correct |
218 ms |
8544 KB |
Output is correct |
29 |
Correct |
222 ms |
8548 KB |
Output is correct |
30 |
Correct |
203 ms |
8504 KB |
Output is correct |
31 |
Correct |
104 ms |
6212 KB |
Output is correct |
32 |
Correct |
49 ms |
2008 KB |
Output is correct |
33 |
Correct |
51 ms |
2484 KB |
Output is correct |
34 |
Correct |
48 ms |
2508 KB |
Output is correct |
35 |
Correct |
29 ms |
2244 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
27 ms |
2204 KB |
Output is correct |
38 |
Correct |
53 ms |
2456 KB |
Output is correct |
39 |
Correct |
110 ms |
2756 KB |
Output is correct |
40 |
Correct |
115 ms |
3660 KB |
Output is correct |
41 |
Correct |
235 ms |
6968 KB |
Output is correct |
42 |
Correct |
117 ms |
6288 KB |
Output is correct |
43 |
Correct |
65 ms |
3392 KB |
Output is correct |
44 |
Correct |
139 ms |
6080 KB |
Output is correct |
45 |
Correct |
141 ms |
6620 KB |
Output is correct |
46 |
Correct |
92 ms |
3704 KB |
Output is correct |
47 |
Correct |
114 ms |
4496 KB |
Output is correct |
48 |
Correct |
109 ms |
4556 KB |
Output is correct |
49 |
Correct |
218 ms |
8544 KB |
Output is correct |
50 |
Correct |
133 ms |
7720 KB |
Output is correct |
51 |
Correct |
94 ms |
5224 KB |
Output is correct |
52 |
Correct |
131 ms |
7864 KB |
Output is correct |
53 |
Correct |
117 ms |
6384 KB |
Output is correct |
54 |
Correct |
148 ms |
7108 KB |
Output is correct |
55 |
Correct |
201 ms |
8584 KB |
Output is correct |