This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i,l,r) for (int i = l; i <= r; i++)
#define FORD(i,l,r) for (int i = l; i >= r; i--)
#define el cout <<"\n"
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&(1LL))
#define Debug(a,n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> vii;
typedef unsigned long long ull;
typedef vector<vector<int>> vvi;
int fastMax(int x, int y)
{
return (((y-x)>>(32-1))&(x^y))^y;
}
const long long N=1e6+5;
const long long base=311;
const long long mod=1e9+7;
const long long INF=1e9+7;
const int d4x[4] = {-1, 0, 1, 0}, d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};
///KhengmepfromLTVHSFTGgoldmedal&&letter<3
long long n,a[N],x;
int res=0,suf[N];
vector<int>lis;
void cal()
{
for(int i=1; i<=n; i++)
{
a[i]=-a[i];
}
for(int i=n; i>=1; i--)
{
auto it=lower_bound(ALL(lis),a[i])-lis.begin();
suf[i]=it+1;
if(it==lis.size())
{
lis.emplace_back(a[i]);
}
else lis[it]=a[i];
}
for(int i=1; i<=n; i++)
{
a[i]=-a[i];
}
res=lis.size();
}
void khengmep()
{
cal();
lis.clear();
for(int i=1; i<=n; i++)
{
int l=lower_bound(ALL(lis),a[i]+x)-lis.begin()+1;
res=max(res,l+suf[i]-1);
auto it=lower_bound(ALL(lis),a[i])-lis.begin();
if(it==lis.size())
{
lis.emplace_back(a[i]);
}
else lis[it]=a[i];
}
cout<<res;
el;
}
void ip()
{
cin>>n>>x;
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
}
int main()
{
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
ip();
khengmep();
}
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'void cal()':
glo.cpp:46:14: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if(it==lis.size())
| ~~^~~~~~~~~~~~
glo.cpp: In function 'void khengmep()':
glo.cpp:67:14: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if(it==lis.size())
| ~~^~~~~~~~~~~~
# | 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... |