#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const int mxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
int n; ll ans = 1; ll x, v[mxN], lst[mxN];
vi l, r;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> x;
F0R(i, n) cin >> v[i];
F0R(i, n){
if(siz(l))
lst[i] = lower_bound(all(l), v[i] + x)-l.begin();
else
lst[i] = 0;
int cur;
if(siz(l))
cur = lower_bound(all(l), v[i]) - l.begin();
else
cur = 0;
if(cur == siz(l)) l.pb(v[i]);
else l[cur] = v[i];
}
R0F(i, n){
//trav(x, r){
// cout << x << ' ';
//}
//cout << endl;
//auto pos = lower_bound(all(r), -v[i]);
//if(pos == r.end()) {
// r.pb(-v[i]);
// ckmax(ans, lst[i] + 1);
// continue;
//}
//*pos = -v[i];
//ckmax(ans, pos - r.begin() + lst[i] + 1);
int cur;
if(siz(r)) cur = lower_bound(all(r), -v[i]) - r.begin();
else cur = 0;
if(cur == siz(r)) r.pb(-v[i]);
else r[cur] = -v[i];
ckmax(ans, lst[i] + cur + 1);
}
cout << ans << nl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
416 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
416 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
5544 KB |
Output is correct |
2 |
Correct |
61 ms |
5368 KB |
Output is correct |
3 |
Correct |
64 ms |
5368 KB |
Output is correct |
4 |
Correct |
62 ms |
5368 KB |
Output is correct |
5 |
Correct |
36 ms |
5756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1664 KB |
Output is correct |
2 |
Correct |
17 ms |
1664 KB |
Output is correct |
3 |
Correct |
15 ms |
1664 KB |
Output is correct |
4 |
Correct |
9 ms |
1792 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
8 ms |
1792 KB |
Output is correct |
7 |
Correct |
12 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2964 KB |
Output is correct |
2 |
Correct |
26 ms |
2968 KB |
Output is correct |
3 |
Correct |
53 ms |
5368 KB |
Output is correct |
4 |
Correct |
36 ms |
5848 KB |
Output is correct |
5 |
Correct |
17 ms |
3072 KB |
Output is correct |
6 |
Correct |
31 ms |
5620 KB |
Output is correct |
7 |
Correct |
33 ms |
6388 KB |
Output is correct |
8 |
Correct |
22 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
416 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
62 ms |
5544 KB |
Output is correct |
28 |
Correct |
61 ms |
5368 KB |
Output is correct |
29 |
Correct |
64 ms |
5368 KB |
Output is correct |
30 |
Correct |
62 ms |
5368 KB |
Output is correct |
31 |
Correct |
36 ms |
5756 KB |
Output is correct |
32 |
Correct |
15 ms |
1664 KB |
Output is correct |
33 |
Correct |
17 ms |
1664 KB |
Output is correct |
34 |
Correct |
15 ms |
1664 KB |
Output is correct |
35 |
Correct |
9 ms |
1792 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
8 ms |
1792 KB |
Output is correct |
38 |
Correct |
12 ms |
1664 KB |
Output is correct |
39 |
Correct |
28 ms |
2964 KB |
Output is correct |
40 |
Correct |
26 ms |
2968 KB |
Output is correct |
41 |
Correct |
53 ms |
5368 KB |
Output is correct |
42 |
Correct |
36 ms |
5848 KB |
Output is correct |
43 |
Correct |
17 ms |
3072 KB |
Output is correct |
44 |
Correct |
31 ms |
5620 KB |
Output is correct |
45 |
Correct |
33 ms |
6388 KB |
Output is correct |
46 |
Correct |
22 ms |
2944 KB |
Output is correct |
47 |
Correct |
30 ms |
2936 KB |
Output is correct |
48 |
Correct |
30 ms |
2944 KB |
Output is correct |
49 |
Correct |
63 ms |
5496 KB |
Output is correct |
50 |
Correct |
36 ms |
5748 KB |
Output is correct |
51 |
Correct |
29 ms |
4852 KB |
Output is correct |
52 |
Correct |
36 ms |
6004 KB |
Output is correct |
53 |
Correct |
33 ms |
5876 KB |
Output is correct |
54 |
Correct |
35 ms |
6644 KB |
Output is correct |
55 |
Correct |
50 ms |
5420 KB |
Output is correct |