#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma omp
#pragma simd
#pragma unroll
#pragma pack
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC target("avx","sse2")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#define int long long
#define fi first
#define se second
#define pb push_back
#define M_PI 3.14159265358979323846
#define set_on(x, i) ((x) | (1LL << i))
#define set_off(x, i) ((x) & ~(1LL << i))
#define get_bit(x, i) ((x >> i) & 1LL)
#define count_bit(x) __builtin_popcountll(x)
#define rep(i, a, b) for(int i=a; i<b; i++)
const int maxn=1e6+5;
const int mxn=1e7+5;
const int N =4e5+5;
int base=313,basej=431;
ll MOD=790972;//
int mod=1e9+7;
int inf=1e18;
typedef pair<int, int> pii;
const int S = 19;
const int LOG = log2(N)+1;
ll sqr(ll x) {
return x*x;
}
ll power(ll a, ll b) {
if (b == 0) return 1 ;
if (b % 2 == 0)
return sqr(power(a, b/2)) ;
return a * (sqr(power(a, b/2)) ) ;}
int n,x,a[N],bit0[N],bit1[N],bit2[N];
vector<int>b1,b2;
void update(int *bit,int pos,int val){
for(;pos<N;pos+=pos&(-pos))bit[pos]=max(bit[pos],val);
}
int get(int *bit,int pos){
int res=0;
for(;pos>0;pos-=pos&(-pos))res=max(res,bit[pos]);
return res;
}
void solve(){
int ans=1;
for(int i=1;i<=n;i++){
int nonadd=lower_bound(b1.begin(),b1.end(),a[i])-b1.begin();
int add=lower_bound(b1.begin(),b1.end(),a[i]+x)-b1.begin();
int mx1=get(bit0,nonadd-1)+1;
int mx2=max(get(bit0,add-1),get(bit1,add-1))+1;
ans=max({ans,mx1,mx2});
update(bit0,nonadd,mx1);
update(bit1,add,mx2);
}
for(int i=1;i<N;i++)bit1[i]=bit0[i]=bit2[i]=0;
for(int i=1;i<=n;i++){
int nonadd=lower_bound(b2.begin(),b2.end(),a[i])-b2.begin();
int add=lower_bound(b2.begin(),b2.end(),a[i]+x)-b2.begin();
int mx1=get(bit0,nonadd-1)+1;
int mx2=max(get(bit0,add-1),get(bit1,add-1))+1;
ans=max({ans,mx1,mx2});
update(bit0,nonadd,mx1);
update(bit1,add,mx2);
}
cout << ans;
}
void input(){
cin >> n >> x; \
b1.pb(-inf); b2.pb(-inf);
for(int i=1;i<=n;i++){
cin >> a[i] ; b1.pb(a[i]);b2.pb(a[i]);
b1.pb(a[i]+x);b2.pb(a[i]-x);
}
sort(b1.begin(),b1.end()); b1.erase(unique(b1.begin(),b1.end()),b1.end());
sort(b2.begin(),b2.end()); b2.erase(unique(b2.begin(),b2.end()),b2.end());
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
// if (fopen("LROP.inp", "r")) {
// freopen("LROP.inp", "r", stdin);
// freopen("LROP.out", "wN", stdout);
// }
int t;t=1;
while(t--){
input();
solve();
}
}
Compilation message
glo.cpp:4: warning: ignoring '#pragma omp ' [-Wunknown-pragmas]
4 | #pragma omp
|
glo.cpp:5: warning: ignoring '#pragma simd ' [-Wunknown-pragmas]
5 | #pragma simd
|
glo.cpp:6: warning: ignoring '#pragma unroll ' [-Wunknown-pragmas]
6 | #pragma unroll
|
glo.cpp:7:9: warning: missing '(' after '#pragma pack' - ignored [-Wpragmas]
7 | #pragma pack
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
5 ms |
10844 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
3 ms |
10844 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
3 ms |
10708 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
4 ms |
10696 KB |
Output is correct |
9 |
Correct |
4 ms |
10844 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
5 ms |
10844 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
3 ms |
10844 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
3 ms |
10708 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
4 ms |
10696 KB |
Output is correct |
9 |
Correct |
4 ms |
10844 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
4 ms |
10844 KB |
Output is correct |
12 |
Correct |
4 ms |
10844 KB |
Output is correct |
13 |
Correct |
3 ms |
10844 KB |
Output is correct |
14 |
Correct |
3 ms |
10652 KB |
Output is correct |
15 |
Correct |
3 ms |
10844 KB |
Output is correct |
16 |
Correct |
3 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10844 KB |
Output is correct |
18 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
5 ms |
10844 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
3 ms |
10844 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
3 ms |
10708 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
4 ms |
10696 KB |
Output is correct |
9 |
Correct |
4 ms |
10844 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
4 ms |
10844 KB |
Output is correct |
12 |
Correct |
4 ms |
10844 KB |
Output is correct |
13 |
Correct |
3 ms |
10844 KB |
Output is correct |
14 |
Correct |
3 ms |
10652 KB |
Output is correct |
15 |
Correct |
3 ms |
10844 KB |
Output is correct |
16 |
Correct |
3 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10844 KB |
Output is correct |
18 |
Correct |
4 ms |
10844 KB |
Output is correct |
19 |
Correct |
5 ms |
10844 KB |
Output is correct |
20 |
Correct |
5 ms |
10844 KB |
Output is correct |
21 |
Correct |
4 ms |
11100 KB |
Output is correct |
22 |
Correct |
4 ms |
10964 KB |
Output is correct |
23 |
Correct |
3 ms |
10968 KB |
Output is correct |
24 |
Correct |
5 ms |
10844 KB |
Output is correct |
25 |
Correct |
4 ms |
10844 KB |
Output is correct |
26 |
Correct |
5 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
21776 KB |
Output is correct |
2 |
Correct |
208 ms |
21824 KB |
Output is correct |
3 |
Correct |
211 ms |
21404 KB |
Output is correct |
4 |
Correct |
204 ms |
21728 KB |
Output is correct |
5 |
Correct |
85 ms |
21400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
12912 KB |
Output is correct |
2 |
Correct |
55 ms |
13040 KB |
Output is correct |
3 |
Correct |
50 ms |
13008 KB |
Output is correct |
4 |
Correct |
24 ms |
12744 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
24 ms |
12744 KB |
Output is correct |
7 |
Correct |
42 ms |
13168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
15024 KB |
Output is correct |
2 |
Correct |
97 ms |
15028 KB |
Output is correct |
3 |
Correct |
197 ms |
22304 KB |
Output is correct |
4 |
Correct |
93 ms |
20388 KB |
Output is correct |
5 |
Correct |
48 ms |
14644 KB |
Output is correct |
6 |
Correct |
86 ms |
20692 KB |
Output is correct |
7 |
Correct |
92 ms |
21952 KB |
Output is correct |
8 |
Correct |
84 ms |
15044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
5 ms |
10844 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
3 ms |
10844 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
3 ms |
10708 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
4 ms |
10696 KB |
Output is correct |
9 |
Correct |
4 ms |
10844 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
4 ms |
10844 KB |
Output is correct |
12 |
Correct |
4 ms |
10844 KB |
Output is correct |
13 |
Correct |
3 ms |
10844 KB |
Output is correct |
14 |
Correct |
3 ms |
10652 KB |
Output is correct |
15 |
Correct |
3 ms |
10844 KB |
Output is correct |
16 |
Correct |
3 ms |
10844 KB |
Output is correct |
17 |
Correct |
3 ms |
10844 KB |
Output is correct |
18 |
Correct |
4 ms |
10844 KB |
Output is correct |
19 |
Correct |
5 ms |
10844 KB |
Output is correct |
20 |
Correct |
5 ms |
10844 KB |
Output is correct |
21 |
Correct |
4 ms |
11100 KB |
Output is correct |
22 |
Correct |
4 ms |
10964 KB |
Output is correct |
23 |
Correct |
3 ms |
10968 KB |
Output is correct |
24 |
Correct |
5 ms |
10844 KB |
Output is correct |
25 |
Correct |
4 ms |
10844 KB |
Output is correct |
26 |
Correct |
5 ms |
10844 KB |
Output is correct |
27 |
Correct |
198 ms |
21776 KB |
Output is correct |
28 |
Correct |
208 ms |
21824 KB |
Output is correct |
29 |
Correct |
211 ms |
21404 KB |
Output is correct |
30 |
Correct |
204 ms |
21728 KB |
Output is correct |
31 |
Correct |
85 ms |
21400 KB |
Output is correct |
32 |
Correct |
46 ms |
12912 KB |
Output is correct |
33 |
Correct |
55 ms |
13040 KB |
Output is correct |
34 |
Correct |
50 ms |
13008 KB |
Output is correct |
35 |
Correct |
24 ms |
12744 KB |
Output is correct |
36 |
Correct |
3 ms |
10844 KB |
Output is correct |
37 |
Correct |
24 ms |
12744 KB |
Output is correct |
38 |
Correct |
42 ms |
13168 KB |
Output is correct |
39 |
Correct |
98 ms |
15024 KB |
Output is correct |
40 |
Correct |
97 ms |
15028 KB |
Output is correct |
41 |
Correct |
197 ms |
22304 KB |
Output is correct |
42 |
Correct |
93 ms |
20388 KB |
Output is correct |
43 |
Correct |
48 ms |
14644 KB |
Output is correct |
44 |
Correct |
86 ms |
20692 KB |
Output is correct |
45 |
Correct |
92 ms |
21952 KB |
Output is correct |
46 |
Correct |
84 ms |
15044 KB |
Output is correct |
47 |
Correct |
104 ms |
15028 KB |
Output is correct |
48 |
Correct |
92 ms |
15080 KB |
Output is correct |
49 |
Correct |
238 ms |
21568 KB |
Output is correct |
50 |
Correct |
107 ms |
20792 KB |
Output is correct |
51 |
Correct |
89 ms |
20124 KB |
Output is correct |
52 |
Correct |
105 ms |
21148 KB |
Output is correct |
53 |
Correct |
97 ms |
20684 KB |
Output is correct |
54 |
Correct |
91 ms |
21668 KB |
Output is correct |
55 |
Correct |
175 ms |
21584 KB |
Output is correct |