#include <bits/stdc++.h>
using namespace std;
const int N=4e5+5;
int n,t[4*N],a[N],f[N],x,h,u,v,k,res; vector <int> ve;
void update(int id,int l,int r)
{
if (l==r)
{
t[id]=h;
return;
}
int m=(l+r)/2;
if (u<=m) update(id*2,l,m); else update(id*2+1,m+1,r);
t[id]=max(t[id*2],t[id*2+1]);
}
int get(int id,int l,int r)
{
if (v<l) return 0;
if (v>=r) return t[id];
int m=(l+r)/2;
return max(get(id*2,l,m),get(id*2+1,m+1,r));
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> x;
x=abs(x);
for (int i=1;i<=n;i++)
{
cin >> a[i];
ve.push_back(a[i]);
ve.push_back(a[i]+x);
}
sort(ve.begin(),ve.end());
ve.resize(unique(ve.begin(),ve.end())-ve.begin());
k=ve.size();
for (int i=1;i<=n;i++)
{
v=lower_bound(ve.begin(),ve.end(),a[i]+x)-ve.begin();
h=get(1,1,k)+1;
u=v+1;
if (f[u]<h)
{
f[u]=h;
update(1,1,k);
res=max(res,f[u]);
}
v=lower_bound(ve.begin(),ve.end(),a[i])-ve.begin();
h=get(1,1,k)+1;
u=v+1;
if (f[u]<h)
{
f[u]=h;
update(1,1,k);
res-max(res,f[u]);
}
}
cout << res;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:56:16: warning: value computed is not used [-Wunused-value]
56 | res-max(res,f[u]);
| ~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
7624 KB |
Output is correct |
2 |
Correct |
156 ms |
7620 KB |
Output is correct |
3 |
Correct |
152 ms |
7624 KB |
Output is correct |
4 |
Correct |
158 ms |
7616 KB |
Output is correct |
5 |
Correct |
60 ms |
5348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
3036 KB |
Output is correct |
2 |
Correct |
43 ms |
3052 KB |
Output is correct |
3 |
Correct |
43 ms |
2964 KB |
Output is correct |
4 |
Incorrect |
20 ms |
2008 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
5588 KB |
Output is correct |
2 |
Correct |
94 ms |
5592 KB |
Output is correct |
3 |
Correct |
213 ms |
10440 KB |
Output is correct |
4 |
Correct |
84 ms |
6852 KB |
Output is correct |
5 |
Correct |
65 ms |
5172 KB |
Output is correct |
6 |
Correct |
104 ms |
9416 KB |
Output is correct |
7 |
Correct |
103 ms |
10180 KB |
Output is correct |
8 |
Correct |
83 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |