#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"
#define int long long
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: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".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
glo.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
3 ms |
21120 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21084 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21336 KB |
Output is correct |
8 |
Correct |
4 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
3 ms |
21120 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21084 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21336 KB |
Output is correct |
8 |
Correct |
4 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21128 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
3 ms |
21084 KB |
Output is correct |
16 |
Correct |
3 ms |
21340 KB |
Output is correct |
17 |
Correct |
3 ms |
21084 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
3 ms |
21120 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21084 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21336 KB |
Output is correct |
8 |
Correct |
4 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21128 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
3 ms |
21084 KB |
Output is correct |
16 |
Correct |
3 ms |
21340 KB |
Output is correct |
17 |
Correct |
3 ms |
21084 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
19 |
Correct |
4 ms |
21080 KB |
Output is correct |
20 |
Correct |
3 ms |
20968 KB |
Output is correct |
21 |
Correct |
4 ms |
21084 KB |
Output is correct |
22 |
Correct |
4 ms |
21176 KB |
Output is correct |
23 |
Correct |
3 ms |
21080 KB |
Output is correct |
24 |
Correct |
3 ms |
21084 KB |
Output is correct |
25 |
Correct |
3 ms |
21336 KB |
Output is correct |
26 |
Correct |
3 ms |
21080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
25152 KB |
Output is correct |
2 |
Correct |
205 ms |
25164 KB |
Output is correct |
3 |
Correct |
205 ms |
25364 KB |
Output is correct |
4 |
Correct |
202 ms |
25364 KB |
Output is correct |
5 |
Correct |
101 ms |
25180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
21092 KB |
Output is correct |
2 |
Correct |
51 ms |
21100 KB |
Output is correct |
3 |
Correct |
50 ms |
21192 KB |
Output is correct |
4 |
Correct |
26 ms |
21192 KB |
Output is correct |
5 |
Correct |
3 ms |
21084 KB |
Output is correct |
6 |
Correct |
28 ms |
21096 KB |
Output is correct |
7 |
Correct |
43 ms |
21188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
23212 KB |
Output is correct |
2 |
Correct |
108 ms |
23192 KB |
Output is correct |
3 |
Correct |
225 ms |
25208 KB |
Output is correct |
4 |
Correct |
104 ms |
26332 KB |
Output is correct |
5 |
Correct |
67 ms |
23788 KB |
Output is correct |
6 |
Correct |
116 ms |
26372 KB |
Output is correct |
7 |
Correct |
118 ms |
27216 KB |
Output is correct |
8 |
Correct |
91 ms |
24320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
21084 KB |
Output is correct |
2 |
Correct |
3 ms |
21120 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21084 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21336 KB |
Output is correct |
8 |
Correct |
4 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21128 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
3 ms |
21084 KB |
Output is correct |
16 |
Correct |
3 ms |
21340 KB |
Output is correct |
17 |
Correct |
3 ms |
21084 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
19 |
Correct |
4 ms |
21080 KB |
Output is correct |
20 |
Correct |
3 ms |
20968 KB |
Output is correct |
21 |
Correct |
4 ms |
21084 KB |
Output is correct |
22 |
Correct |
4 ms |
21176 KB |
Output is correct |
23 |
Correct |
3 ms |
21080 KB |
Output is correct |
24 |
Correct |
3 ms |
21084 KB |
Output is correct |
25 |
Correct |
3 ms |
21336 KB |
Output is correct |
26 |
Correct |
3 ms |
21080 KB |
Output is correct |
27 |
Correct |
202 ms |
25152 KB |
Output is correct |
28 |
Correct |
205 ms |
25164 KB |
Output is correct |
29 |
Correct |
205 ms |
25364 KB |
Output is correct |
30 |
Correct |
202 ms |
25364 KB |
Output is correct |
31 |
Correct |
101 ms |
25180 KB |
Output is correct |
32 |
Correct |
51 ms |
21092 KB |
Output is correct |
33 |
Correct |
51 ms |
21100 KB |
Output is correct |
34 |
Correct |
50 ms |
21192 KB |
Output is correct |
35 |
Correct |
26 ms |
21192 KB |
Output is correct |
36 |
Correct |
3 ms |
21084 KB |
Output is correct |
37 |
Correct |
28 ms |
21096 KB |
Output is correct |
38 |
Correct |
43 ms |
21188 KB |
Output is correct |
39 |
Correct |
107 ms |
23212 KB |
Output is correct |
40 |
Correct |
108 ms |
23192 KB |
Output is correct |
41 |
Correct |
225 ms |
25208 KB |
Output is correct |
42 |
Correct |
104 ms |
26332 KB |
Output is correct |
43 |
Correct |
67 ms |
23788 KB |
Output is correct |
44 |
Correct |
116 ms |
26372 KB |
Output is correct |
45 |
Correct |
118 ms |
27216 KB |
Output is correct |
46 |
Correct |
91 ms |
24320 KB |
Output is correct |
47 |
Correct |
104 ms |
24100 KB |
Output is correct |
48 |
Correct |
105 ms |
24216 KB |
Output is correct |
49 |
Correct |
239 ms |
27092 KB |
Output is correct |
50 |
Correct |
104 ms |
26500 KB |
Output is correct |
51 |
Correct |
93 ms |
26116 KB |
Output is correct |
52 |
Correct |
137 ms |
26488 KB |
Output is correct |
53 |
Correct |
124 ms |
26460 KB |
Output is correct |
54 |
Correct |
127 ms |
27236 KB |
Output is correct |
55 |
Correct |
183 ms |
27132 KB |
Output is correct |