#include<bits/stdc++.h>
#define FileName "test"
#define ll long long
#define pb emplace_back
#define mp make_pair
#define x first
#define y second
//#define LuckyAurora
#pragma GCC optimization ("O3")
using namespace std;
const int N = 2e5 + 3;
int t[N], n, x, res = 0, pos, cur0, cur1;
vector<int> v;
struct TSegment {
vector<int> l, h, st;
TSegment() {}
TSegment(int n) {l.resize(4 * n + 1), h.resize(4 * n + 1), st.resize(4 * n + 1);}
void Build(int x, int low, int high)
{
l[x] = low, h[x] = high;
if(l[x] == h[x]) {
st[x] = 0;
return;
}
int mid = (low + high) >> 1;
Build(x << 1, low, mid);
Build(x << 1 | 1, mid + 1, high);
}
void Update(int x, int pos, int val)
{
if(l[x] > pos || h[x] < pos) return;
if(l[x] == h[x]) {
st[x] = max(st[x], val);
return;
}
Update(x << 1, pos, val);
Update(x << 1 | 1, pos, val);
st[x] = max(st[x << 1], st[x << 1 | 1]);
}
int Query(int x, int low, int high)
{
if(l[x] > high || h[x] < low) return 0;
if(l[x] >= low && h[x] <= high) return st[x];
return max(Query(x << 1, low, high), Query(x << 1 | 1, low, high));
}
} f0, f1;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n >> x;
for(int i = 1; i <= n; ++i) cin >> t[i], v.pb(t[i]);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
f0 = TSegment(int(v.size()));
f1 = TSegment(int(v.size()));
f0.Build(1, 1, int(v.size()));
f1.Build(1, 1, int(v.size()));
for(int i = 1; i <= n; ++i) {
pos = upper_bound(v.begin(), v.end(), t[i] + x - 1) - v.begin();
t[i] = lower_bound(v.begin(), v.end(), t[i]) - v.begin();
cur1 = cur0 = -1;
if(t[i] >= 1) cur0 = f0.Query(1, 1, t[i]) + 1;
else cur0 = 1;
if(pos >= 1 && pos <= n) cur1 = f0.Query(1, 1, pos) + 1;
if(t[i] >= 1) cur1 = max(cur1, f1.Query(1, 1, t[i]) + 1);
else cur1 = max(cur1, 1);
f0.Update(1, t[i] + 1, cur0);
f1.Update(1, t[i] + 1, cur1);
res = max({res, cur0, cur1});
}
cout << res;
}
Compilation message
glo.cpp:9:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
glo.cpp: In function 'int main()':
glo.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("test.inp", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("test.out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
392 KB |
Output is correct |
21 |
Correct |
4 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
507 ms |
22892 KB |
Output is correct |
2 |
Correct |
501 ms |
22816 KB |
Output is correct |
3 |
Correct |
490 ms |
22896 KB |
Output is correct |
4 |
Correct |
506 ms |
22896 KB |
Output is correct |
5 |
Correct |
219 ms |
12528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
6108 KB |
Output is correct |
2 |
Correct |
93 ms |
6136 KB |
Output is correct |
3 |
Correct |
94 ms |
6148 KB |
Output is correct |
4 |
Correct |
49 ms |
3448 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
50 ms |
3576 KB |
Output is correct |
7 |
Correct |
79 ms |
6164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
11636 KB |
Output is correct |
2 |
Correct |
190 ms |
11664 KB |
Output is correct |
3 |
Correct |
470 ms |
22868 KB |
Output is correct |
4 |
Correct |
199 ms |
12784 KB |
Output is correct |
5 |
Correct |
114 ms |
11252 KB |
Output is correct |
6 |
Correct |
206 ms |
20976 KB |
Output is correct |
7 |
Correct |
213 ms |
21616 KB |
Output is correct |
8 |
Correct |
144 ms |
11608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
392 KB |
Output is correct |
21 |
Correct |
4 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
507 ms |
22892 KB |
Output is correct |
28 |
Correct |
501 ms |
22816 KB |
Output is correct |
29 |
Correct |
490 ms |
22896 KB |
Output is correct |
30 |
Correct |
506 ms |
22896 KB |
Output is correct |
31 |
Correct |
219 ms |
12528 KB |
Output is correct |
32 |
Correct |
95 ms |
6108 KB |
Output is correct |
33 |
Correct |
93 ms |
6136 KB |
Output is correct |
34 |
Correct |
94 ms |
6148 KB |
Output is correct |
35 |
Correct |
49 ms |
3448 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
50 ms |
3576 KB |
Output is correct |
38 |
Correct |
79 ms |
6164 KB |
Output is correct |
39 |
Correct |
194 ms |
11636 KB |
Output is correct |
40 |
Correct |
190 ms |
11664 KB |
Output is correct |
41 |
Correct |
470 ms |
22868 KB |
Output is correct |
42 |
Correct |
199 ms |
12784 KB |
Output is correct |
43 |
Correct |
114 ms |
11252 KB |
Output is correct |
44 |
Correct |
206 ms |
20976 KB |
Output is correct |
45 |
Correct |
213 ms |
21616 KB |
Output is correct |
46 |
Correct |
144 ms |
11608 KB |
Output is correct |
47 |
Correct |
217 ms |
11688 KB |
Output is correct |
48 |
Correct |
216 ms |
11808 KB |
Output is correct |
49 |
Correct |
525 ms |
22824 KB |
Output is correct |
50 |
Correct |
212 ms |
12676 KB |
Output is correct |
51 |
Correct |
176 ms |
11908 KB |
Output is correct |
52 |
Correct |
267 ms |
22132 KB |
Output is correct |
53 |
Correct |
214 ms |
22260 KB |
Output is correct |
54 |
Correct |
227 ms |
23012 KB |
Output is correct |
55 |
Correct |
368 ms |
22892 KB |
Output is correct |