#include <bits/stdc++.h>
#define ll long long
#define LOG 19
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define FIRST_BIT(mask) __builtin_ctz((mask)&(-mask))
#define ERASE_BIT(mask) (mask)^((mask)&(-mask))
#define left _left
#define right _right
#define task "t"
using namespace std;
const ll INF=1e18;
const int iat=2e6+9;
const int mod=1e9+7;
void fast_IO()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
}
int n,x,t[iat],tx[iat],sz,store[iat];
void compress()
{
vector <int> v;
for(int i=1; i<=n; i++)
{
v.push_back(t[i]);
v.push_back(t[i]+x);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
sz=v.size();
for(int i=1; i<=n; i++)
{
tx[i]=lower_bound(v.begin(),v.end(),t[i]+x)-v.begin()+1;
t[i]=lower_bound(v.begin(),v.end(),t[i])-v.begin()+1;
}
}
struct Segment
{
int st[iat];
void init()
{
memset(st,0,sizeof(st));
}
void update(int id, int l, int r, int pos, int val)
{
if(l==r)
{
st[id]=max(st[id],val);
return;
}
int mid=(l+r)/2;
if(pos<=mid)update(2*id,l,mid,pos,val);
else update(2*id+1,mid+1,r,pos,val);
st[id]=max(st[2*id],st[2*id+1]);
}
int getMax(int id, int l, int r, int u, int v)
{
if(l>v || r<u)return 0;
if(u<=l && r<=v)return st[id];
int mid=(l+r)/2;
return max(getMax(2*id,l,mid,u,v),getMax(2*id+1,mid+1,r,u,v));
}
}tree;
signed main()
{
fast_IO();
cin>>n>>x;
for(int i=1; i<=n; i++)cin>>t[i];
compress();
int ans=0;
for(int i=n; i>=1; i--)
{
store[i]=tree.getMax(1,1,sz,tx[i]+1,sz)+1;
tree.update(1,1,sz,tx[i],store[i]);
ans=max(ans,store[i]);
}
tree.init();
for(int i=1; i<=n; i++)
{
ans=max(ans,store[i]+tree.getMax(1,1,sz,1,tx[i]-1));
int tmp=tree.getMax(1,1,sz,1,t[i]-1)+1;
tree.update(1,1,sz,t[i],tmp);
}
cout<<ans;
}
Compilation message
glo.cpp: In function 'void fast_IO()':
glo.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12892 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12892 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
2 ms |
12888 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
2 ms |
12892 KB |
Output is correct |
17 |
Correct |
2 ms |
12892 KB |
Output is correct |
18 |
Correct |
2 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12892 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
2 ms |
12888 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
2 ms |
12892 KB |
Output is correct |
17 |
Correct |
2 ms |
12892 KB |
Output is correct |
18 |
Correct |
2 ms |
12892 KB |
Output is correct |
19 |
Correct |
2 ms |
12892 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
2 ms |
12892 KB |
Output is correct |
22 |
Correct |
3 ms |
12892 KB |
Output is correct |
23 |
Correct |
2 ms |
12960 KB |
Output is correct |
24 |
Correct |
2 ms |
12892 KB |
Output is correct |
25 |
Correct |
2 ms |
12892 KB |
Output is correct |
26 |
Correct |
2 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
15108 KB |
Output is correct |
2 |
Correct |
198 ms |
14928 KB |
Output is correct |
3 |
Correct |
200 ms |
14940 KB |
Output is correct |
4 |
Correct |
192 ms |
14920 KB |
Output is correct |
5 |
Correct |
95 ms |
15000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
12888 KB |
Output is correct |
2 |
Correct |
54 ms |
12876 KB |
Output is correct |
3 |
Correct |
55 ms |
13072 KB |
Output is correct |
4 |
Correct |
25 ms |
12880 KB |
Output is correct |
5 |
Correct |
2 ms |
12888 KB |
Output is correct |
6 |
Correct |
28 ms |
12880 KB |
Output is correct |
7 |
Correct |
40 ms |
12880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
12888 KB |
Output is correct |
2 |
Correct |
101 ms |
12996 KB |
Output is correct |
3 |
Correct |
217 ms |
15112 KB |
Output is correct |
4 |
Correct |
101 ms |
15016 KB |
Output is correct |
5 |
Correct |
65 ms |
12988 KB |
Output is correct |
6 |
Correct |
121 ms |
15096 KB |
Output is correct |
7 |
Correct |
116 ms |
14912 KB |
Output is correct |
8 |
Correct |
82 ms |
12984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12892 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
2 ms |
12888 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
2 ms |
12892 KB |
Output is correct |
17 |
Correct |
2 ms |
12892 KB |
Output is correct |
18 |
Correct |
2 ms |
12892 KB |
Output is correct |
19 |
Correct |
2 ms |
12892 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
2 ms |
12892 KB |
Output is correct |
22 |
Correct |
3 ms |
12892 KB |
Output is correct |
23 |
Correct |
2 ms |
12960 KB |
Output is correct |
24 |
Correct |
2 ms |
12892 KB |
Output is correct |
25 |
Correct |
2 ms |
12892 KB |
Output is correct |
26 |
Correct |
2 ms |
12892 KB |
Output is correct |
27 |
Correct |
231 ms |
15108 KB |
Output is correct |
28 |
Correct |
198 ms |
14928 KB |
Output is correct |
29 |
Correct |
200 ms |
14940 KB |
Output is correct |
30 |
Correct |
192 ms |
14920 KB |
Output is correct |
31 |
Correct |
95 ms |
15000 KB |
Output is correct |
32 |
Correct |
47 ms |
12888 KB |
Output is correct |
33 |
Correct |
54 ms |
12876 KB |
Output is correct |
34 |
Correct |
55 ms |
13072 KB |
Output is correct |
35 |
Correct |
25 ms |
12880 KB |
Output is correct |
36 |
Correct |
2 ms |
12888 KB |
Output is correct |
37 |
Correct |
28 ms |
12880 KB |
Output is correct |
38 |
Correct |
40 ms |
12880 KB |
Output is correct |
39 |
Correct |
103 ms |
12888 KB |
Output is correct |
40 |
Correct |
101 ms |
12996 KB |
Output is correct |
41 |
Correct |
217 ms |
15112 KB |
Output is correct |
42 |
Correct |
101 ms |
15016 KB |
Output is correct |
43 |
Correct |
65 ms |
12988 KB |
Output is correct |
44 |
Correct |
121 ms |
15096 KB |
Output is correct |
45 |
Correct |
116 ms |
14912 KB |
Output is correct |
46 |
Correct |
82 ms |
12984 KB |
Output is correct |
47 |
Correct |
126 ms |
13056 KB |
Output is correct |
48 |
Correct |
102 ms |
13080 KB |
Output is correct |
49 |
Correct |
241 ms |
15112 KB |
Output is correct |
50 |
Correct |
98 ms |
14932 KB |
Output is correct |
51 |
Correct |
104 ms |
14972 KB |
Output is correct |
52 |
Correct |
133 ms |
15004 KB |
Output is correct |
53 |
Correct |
123 ms |
14932 KB |
Output is correct |
54 |
Correct |
136 ms |
14936 KB |
Output is correct |
55 |
Correct |
175 ms |
15000 KB |
Output is correct |