#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
#define int long long
const int N=2e5+10;
int n, x, a[N], ans[N];
signed main()
{
setIO();
cin >> n >> x;
FOR(i, 0, n) cin >> a[i];
vi lds;
for(int i=n-1; i>=0; i--){
int l=-1, r=sz(lds)-1;
while(l<r){
int m=(l+r+1)/2;
if(lds[m]>a[i]-x) l=m;
else r=m-1;
}
ans[i]=l+2;
l=0, r=sz(lds);
while(l<r){
int m=(l+r)/2;
if(lds[m]>a[i]) l=m+1;
else r=m;
}
if(l==sz(lds)) lds.pb(a[i]);
else lds[l]=a[i];
}
vi lis; int mx=0;
FOR(i, 0, n)
{
int l=0, r=sz(lis);
while(l<r){
int m=(l+r)/2;
if(a[i]>lis[m]) l=m+1;
else r=m;
}
if(l==sz(lis)) lis.pb(a[i]);
else lis[l]=a[i];
mx=max(mx, l+ans[i]);
}
cout << mx;
}
Compilation message
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
3396 KB |
Output is correct |
2 |
Correct |
57 ms |
5360 KB |
Output is correct |
3 |
Correct |
59 ms |
5364 KB |
Output is correct |
4 |
Correct |
56 ms |
5320 KB |
Output is correct |
5 |
Correct |
28 ms |
5700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1060 KB |
Output is correct |
2 |
Correct |
12 ms |
1468 KB |
Output is correct |
3 |
Correct |
13 ms |
1472 KB |
Output is correct |
4 |
Correct |
7 ms |
1640 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
7 ms |
1616 KB |
Output is correct |
7 |
Correct |
10 ms |
1576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1868 KB |
Output is correct |
2 |
Correct |
22 ms |
1892 KB |
Output is correct |
3 |
Correct |
46 ms |
3432 KB |
Output is correct |
4 |
Correct |
29 ms |
4604 KB |
Output is correct |
5 |
Correct |
15 ms |
2384 KB |
Output is correct |
6 |
Correct |
24 ms |
4428 KB |
Output is correct |
7 |
Correct |
42 ms |
4420 KB |
Output is correct |
8 |
Correct |
17 ms |
1900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
51 ms |
3396 KB |
Output is correct |
28 |
Correct |
57 ms |
5360 KB |
Output is correct |
29 |
Correct |
59 ms |
5364 KB |
Output is correct |
30 |
Correct |
56 ms |
5320 KB |
Output is correct |
31 |
Correct |
28 ms |
5700 KB |
Output is correct |
32 |
Correct |
13 ms |
1060 KB |
Output is correct |
33 |
Correct |
12 ms |
1468 KB |
Output is correct |
34 |
Correct |
13 ms |
1472 KB |
Output is correct |
35 |
Correct |
7 ms |
1640 KB |
Output is correct |
36 |
Correct |
1 ms |
320 KB |
Output is correct |
37 |
Correct |
7 ms |
1616 KB |
Output is correct |
38 |
Correct |
10 ms |
1576 KB |
Output is correct |
39 |
Correct |
21 ms |
1868 KB |
Output is correct |
40 |
Correct |
22 ms |
1892 KB |
Output is correct |
41 |
Correct |
46 ms |
3432 KB |
Output is correct |
42 |
Correct |
29 ms |
4604 KB |
Output is correct |
43 |
Correct |
15 ms |
2384 KB |
Output is correct |
44 |
Correct |
24 ms |
4428 KB |
Output is correct |
45 |
Correct |
42 ms |
4420 KB |
Output is correct |
46 |
Correct |
17 ms |
1900 KB |
Output is correct |
47 |
Correct |
26 ms |
2740 KB |
Output is correct |
48 |
Correct |
26 ms |
2760 KB |
Output is correct |
49 |
Correct |
58 ms |
5256 KB |
Output is correct |
50 |
Correct |
30 ms |
5748 KB |
Output is correct |
51 |
Correct |
30 ms |
4572 KB |
Output is correct |
52 |
Correct |
32 ms |
5852 KB |
Output is correct |
53 |
Correct |
24 ms |
5820 KB |
Output is correct |
54 |
Correct |
32 ms |
6528 KB |
Output is correct |
55 |
Correct |
49 ms |
5532 KB |
Output is correct |