이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
#define bitm 262144
int n,x,maximum;
int val[200069];
int lis[200069];
int bit[262169];
vector<int> compress;
unordered_map<int,int> um;
void addl(int i, int y) {
while (i<=bitm) {
bit[i]=max(bit[i],y);
i+=(i&-i);
}
}
int findl(int i) {
int rtn=0;
while (i) {
rtn=max(rtn,bit[i]);
i-=(i&-i);
}
return rtn;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 1; i < 200069; i++) {
lis[i]=INT_MAX;
}
cin>>n>>x;
for (int i = 0; i < n; i++) {
cin>>val[i];
compress.push_back(val[i]);
}
/*sort(all(compress));
for (int i = 0; i < n; i++) {
um[compress[i]]=i+1;
}*/
for (int i = 0; i < n; i++) {
int tmp=lower_bound(lis,lis+200069,val[i]+x)-lis;
tmp=max(tmp,findl(val[i]-1)+1);
addl(val[i],tmp);
maximum=max(maximum,tmp);
tmp=lower_bound(lis,lis+200069,val[i])-lis;
lis[tmp]=val[i];
maximum=max(maximum,tmp);
}
cout<<maximum<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |