#include <bits/stdc++.h>
#define int long long
#define debug cout << "ok\n";
#define SQR(x) (1LL * ((x) * (x)))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pli pair<ll,int>
#define vi vector<int>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;
using namespace std;
const int M = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);
const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
template<class _, class __>
bool minimize(_ &x, const __ y){
if(x > y){
x = y;
return true;
} else return false;
}
template<class _, class __>
bool maximize(_ &x, const __ y){
if(x < y){
x = y;
return true;
} else return false;
}
template<class _,class __>
void Add(_ &x, const __ y) {
x += y;
if (x >= M) {
x -= M;
}
return;
}
template<class _,class __>
void Diff(_ &x, const __ y) {
x -= y;
if (x < 0) {
x += M;
}
return;
}
//--------------------------------------------------------------
const int MaxN = 1e6+7;
int n,x,a[MaxN];
vi nen;
struct SegmentTree {
int Tr[MaxN*4];
void UT(int id,int l,int r,int u,int v) {
if (nen[l] > u || nen[r] < u) return;
if (l == r) {
maximize(Tr[id],v);
return;
}
int m = (l+r) >> 1;
UT(id<<1,l,m,u,v);
UT(id<<1|1,m+1,r,u,v);
Tr[id] = max(Tr[id<<1],Tr[id<<1|1]);
return;
}
void Upd(int u,int v) {
UT(1,0,(int)nen.size()-1,u,v);
}
int GV(int id,int l,int r,int u) {
if (nen[l] >= u) return 0;
if (nen[r] < u) return Tr[id];
if (l == r) return 0;
int m = (l+r) >> 1;
return max(GV(id<<1,l,m,u),GV(id<<1|1,m+1,r,u));
}
int Get(int u) {
return GV(1,0,(int)nen.size()-1,u);
}
}Seg[2];
void sol() {
cin >> n >> x;
for (int i=1;i<=n;i++) {
cin >> a[i];
nen.pb(a[i]);
}
sort(nen.begin(),nen.end());
nen.erase(unique(nen.begin(),nen.end()),nen.end());
for (int i=1;i<=n;i++) {
int tmp1 = Seg[0].Get(a[i]) + 1;
int tmp2 = max(Seg[0].Get(a[i]+x),Seg[1].Get(a[i])) + 1;
Seg[0].Upd(a[i],tmp1);
Seg[1].Upd(a[i],tmp2);
}
cout << max(Seg[0].Tr[1],Seg[1].Tr[1]);
}
signed main() {
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
FAST
int t=1;
// cin >> t;
while (t--) sol();
}
| # | 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... |