#include <bits/stdc++.h>
using namespace std;
//#define int long long
struct node{
int s, e, m;
int v = 0;
node *l = nullptr, *r = nullptr;
node(int _s, int _e){
s = _s, e = _e, m = (s+e)/2;
}
void deletefkfkfk(){
if (l != nullptr) l->deletefkfkfk(), delete l;
if (r != nullptr) r->deletefkfkfk(), delete r;
}
void make_l(){
if (l == nullptr) l = new node(s, m);
}
void make_r(){
if (r == nullptr) r = new node(m+1, e);
}
void update(int x, int y){
if (s == e) {v = max(v, y); return;}
if (x <= m) make_l(), l->update(x, y), v = max(v, l->v);
else make_r(), r->update(x, y), v = max(v, r->v);
}
int query(int x, int y){
//cout << s << ' ' << e << '\n';
if (x <= s && e <= y) return v;
if (y <= m) {
if (l == nullptr) return 0;
return l->query(x, y);
}
else if (x > m) {
if (r == nullptr) return 0;
return r->query(x, y);
}
else {
if (l == nullptr && r == nullptr) return 0;
if (l == nullptr) return r->query(m+1, y);
if (r == nullptr) return l->query(x, m);
return max(l->query(x, m), r->query(m+1, y));
}
}
};
main(){
int n, bruh; cin >> n; cin >> bruh;
int arr[n];
for (int x = 0; x < n; x++) cin >> arr[x];
node st2(0, 2000000000), st3(0, 2000000000);
int plis[n];
int slis[n];
for (int x = n-1; x > -1; x--){
slis[x] = st2.query(arr[x]+1, 2000000000)+1;
st2.update(arr[x], slis[x]);
}
int ans = 0;
for (int x = 0; x < n; x++){
plis[x] = st3.query(0, arr[x]-1)+1;
ans = max(ans, st3.query(0, arr[x] + bruh - 1) + slis[x]);
st3.update(arr[x], plis[x]);
}
cout << ans;
}
Compilation message
glo.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
2260 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Correct |
3 ms |
2260 KB |
Output is correct |
22 |
Correct |
4 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
1236 KB |
Output is correct |
24 |
Correct |
2 ms |
1236 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
555 ms |
256320 KB |
Output is correct |
2 |
Correct |
619 ms |
256380 KB |
Output is correct |
3 |
Correct |
538 ms |
256392 KB |
Output is correct |
4 |
Correct |
558 ms |
256356 KB |
Output is correct |
5 |
Correct |
243 ms |
139124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
73168 KB |
Output is correct |
2 |
Correct |
132 ms |
73084 KB |
Output is correct |
3 |
Correct |
139 ms |
73064 KB |
Output is correct |
4 |
Correct |
78 ms |
39288 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
45 ms |
7836 KB |
Output is correct |
7 |
Correct |
87 ms |
52172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
136792 KB |
Output is correct |
2 |
Correct |
259 ms |
136620 KB |
Output is correct |
3 |
Correct |
566 ms |
256452 KB |
Output is correct |
4 |
Correct |
251 ms |
139108 KB |
Output is correct |
5 |
Correct |
107 ms |
20812 KB |
Output is correct |
6 |
Correct |
155 ms |
39344 KB |
Output is correct |
7 |
Correct |
166 ms |
40012 KB |
Output is correct |
8 |
Correct |
174 ms |
98964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
2260 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Correct |
3 ms |
2260 KB |
Output is correct |
22 |
Correct |
4 ms |
2260 KB |
Output is correct |
23 |
Correct |
2 ms |
1236 KB |
Output is correct |
24 |
Correct |
2 ms |
1236 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
555 ms |
256320 KB |
Output is correct |
28 |
Correct |
619 ms |
256380 KB |
Output is correct |
29 |
Correct |
538 ms |
256392 KB |
Output is correct |
30 |
Correct |
558 ms |
256356 KB |
Output is correct |
31 |
Correct |
243 ms |
139124 KB |
Output is correct |
32 |
Correct |
118 ms |
73168 KB |
Output is correct |
33 |
Correct |
132 ms |
73084 KB |
Output is correct |
34 |
Correct |
139 ms |
73064 KB |
Output is correct |
35 |
Correct |
78 ms |
39288 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
45 ms |
7836 KB |
Output is correct |
38 |
Correct |
87 ms |
52172 KB |
Output is correct |
39 |
Correct |
255 ms |
136792 KB |
Output is correct |
40 |
Correct |
259 ms |
136620 KB |
Output is correct |
41 |
Correct |
566 ms |
256452 KB |
Output is correct |
42 |
Correct |
251 ms |
139108 KB |
Output is correct |
43 |
Correct |
107 ms |
20812 KB |
Output is correct |
44 |
Correct |
155 ms |
39344 KB |
Output is correct |
45 |
Correct |
166 ms |
40012 KB |
Output is correct |
46 |
Correct |
174 ms |
98964 KB |
Output is correct |
47 |
Correct |
266 ms |
137636 KB |
Output is correct |
48 |
Correct |
254 ms |
137620 KB |
Output is correct |
49 |
Correct |
536 ms |
256388 KB |
Output is correct |
50 |
Correct |
240 ms |
138992 KB |
Output is correct |
51 |
Correct |
127 ms |
21620 KB |
Output is correct |
52 |
Correct |
237 ms |
41480 KB |
Output is correct |
53 |
Correct |
183 ms |
41364 KB |
Output is correct |
54 |
Correct |
176 ms |
42128 KB |
Output is correct |
55 |
Correct |
395 ms |
185180 KB |
Output is correct |