#include <bits/stdc++.h>
using namespace std;
struct MaxSegtree {
vector<int> tree;
MaxSegtree(int N) {
tree.resize(4*N);
}
void upd(int idx, int s, int e, int x, int y) {
if(x < s || e < x) return;
if(s == e) {
tree[idx] = y;
return;
}
int m = s+e >> 1;
upd(idx*2, s, m, x, y);
upd(idx*2+1, m+1, e, x, y);
tree[idx] = max(tree[idx*2], tree[idx*2+1]);
}
int Max(int idx, int s, int e, int l, int r) {
if(r < s || e < l) return 0;
if(l <= s && e <= r) return tree[idx];
int m = s+e >> 1;
return max(Max(idx*2, s, m, l, r), Max(idx*2+1, m+1, e, l, r));
}
};
vector<int> S;
int A[200009];
inline int get(int x) {
return lower_bound(S.begin(), S.end(), x) - S.begin() + 1;
}
int main() {
int N, x; scanf("%d%d",&N,&x);
for(int i=1; i<=N; i++) {
scanf("%d",&A[i]);
S.push_back(A[i]);
S.push_back(A[i] + x);
}
sort(S.begin(), S.end()); S.resize(unique(S.begin(), S.end()) - S.begin());
MaxSegtree S1(2*N), S2(2*N);
int ans = 0;
for(int i=1; i<=N; i++) {
int m1 = S1.Max(1, 1, 2*N, 1, get(A[i]) - 1) + 1;
int m2 = max(S1.Max(1, 1, 2*N, 1, get(A[i] + x) - 1), S2.Max(1, 1, 2*N, 1, get(A[i] + x) - 1)) + 1;
S1.upd(1, 1, 2*N, get(A[i]), m1); S2.upd(1, 1, 2*N, get(A[i] + x), m2);
ans = max({ans, m1, m2});
}
printf("%d",ans);
return 0;
}
Compilation message
glo.cpp: In member function 'void MaxSegtree::upd(int, int, int, int, int)':
glo.cpp:15:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s+e >> 1;
~^~
glo.cpp: In member function 'int MaxSegtree::Max(int, int, int, int, int)':
glo.cpp:23:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s+e >> 1;
~^~
glo.cpp: In function 'int main()':
glo.cpp:36:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int N, x; scanf("%d%d",&N,&x);
~~~~~^~~~~~~~~~~~~~
glo.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&A[i]);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
256 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 |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 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 |
430 ms |
17284 KB |
Output is correct |
2 |
Correct |
431 ms |
17276 KB |
Output is correct |
3 |
Correct |
402 ms |
17380 KB |
Output is correct |
4 |
Correct |
431 ms |
17260 KB |
Output is correct |
5 |
Correct |
179 ms |
16488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
4592 KB |
Output is correct |
2 |
Correct |
94 ms |
4720 KB |
Output is correct |
3 |
Correct |
89 ms |
4592 KB |
Output is correct |
4 |
Correct |
43 ms |
4464 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
45 ms |
4464 KB |
Output is correct |
7 |
Correct |
70 ms |
4820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
8812 KB |
Output is correct |
2 |
Correct |
190 ms |
8912 KB |
Output is correct |
3 |
Correct |
448 ms |
17352 KB |
Output is correct |
4 |
Correct |
183 ms |
16528 KB |
Output is correct |
5 |
Correct |
109 ms |
8684 KB |
Output is correct |
6 |
Correct |
189 ms |
15884 KB |
Output is correct |
7 |
Correct |
195 ms |
16612 KB |
Output is correct |
8 |
Correct |
146 ms |
8940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
256 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 |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 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 |
430 ms |
17284 KB |
Output is correct |
28 |
Correct |
431 ms |
17276 KB |
Output is correct |
29 |
Correct |
402 ms |
17380 KB |
Output is correct |
30 |
Correct |
431 ms |
17260 KB |
Output is correct |
31 |
Correct |
179 ms |
16488 KB |
Output is correct |
32 |
Correct |
94 ms |
4592 KB |
Output is correct |
33 |
Correct |
94 ms |
4720 KB |
Output is correct |
34 |
Correct |
89 ms |
4592 KB |
Output is correct |
35 |
Correct |
43 ms |
4464 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
37 |
Correct |
45 ms |
4464 KB |
Output is correct |
38 |
Correct |
70 ms |
4820 KB |
Output is correct |
39 |
Correct |
190 ms |
8812 KB |
Output is correct |
40 |
Correct |
190 ms |
8912 KB |
Output is correct |
41 |
Correct |
448 ms |
17352 KB |
Output is correct |
42 |
Correct |
183 ms |
16528 KB |
Output is correct |
43 |
Correct |
109 ms |
8684 KB |
Output is correct |
44 |
Correct |
189 ms |
15884 KB |
Output is correct |
45 |
Correct |
195 ms |
16612 KB |
Output is correct |
46 |
Correct |
146 ms |
8940 KB |
Output is correct |
47 |
Correct |
188 ms |
8944 KB |
Output is correct |
48 |
Correct |
190 ms |
8940 KB |
Output is correct |
49 |
Correct |
442 ms |
17256 KB |
Output is correct |
50 |
Correct |
187 ms |
16612 KB |
Output is correct |
51 |
Correct |
168 ms |
12520 KB |
Output is correct |
52 |
Correct |
218 ms |
16740 KB |
Output is correct |
53 |
Correct |
202 ms |
16712 KB |
Output is correct |
54 |
Correct |
211 ms |
17384 KB |
Output is correct |
55 |
Correct |
345 ms |
17252 KB |
Output is correct |