/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e15 + 7;
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<ll> ar , ra;
std::vector<ll> lis , lde;
std::set<llll> st;
ll crlis = 0 , crlde = 0;
ll addlis(ll val){
ll l = 0 , r = crlis;
while(r > l){
ll md = (l + r + 1)/2;
if(lis[md] >= val){
r = md - 1;
}
else{
l = md;
}
}
if(lis[0] == -1 || lis[0] >= val){
lis[0] = val;
return 1;
}
crlis = std::max(crlis , l + 1);
lis[l + 1] = val;
return l+2;
}
ll addlde(ll val){
ll l = 0 , r = crlde;
while(r > l){
ll md = (l + r + 1)/2;
if(lde[md] > val){
l = md;
}
else{
r = md - 1;
}
}
if(lde[0] == -1 || lde[0] <= val){
lde[0] = val;
return 1;
}
crlde = std::max(crlde , l + 1);
lde[l + 1] = val;
return l + 2;
}
ll check(ll val){
ll l = 0 , r = crlde;
while(r > l){
ll md = (l + r + 1)/2;
if(lde[md] > val){
l = md;
}
else{
r = md - 1;
}
}
if(lde[0] == -1 || lde[0] <= val){
return 0;
}
return l+1;
}
void solve(){
std::cin >> n >> m;
std::vector<ll> mem(n , 0);
ar.resize(n , -1);
ra.resize(n , -1);
lde.resize(n , -1);
lis.resize(n , -1);
ll ans = 0;
for(ll i = 0;n>i;i++){
ll x;std::cin >> x;
ar[i] = x;
mem[i] = addlis(x);
ans = std::max(ans , mem[i]);
}
for(ll i = n-1;0<=i;i--){
ll y = check(ar[i]);
ans = std::max(ans , mem[i] + y);
addlde(ar[i] + m);
}
std::cout << ans << "\n";
return;/**/
}
signed main(){
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}/**/
Compilation message
glo.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
glo.cpp: In function 'int main()':
glo.cpp:108:8: warning: unused variable 'o' [-Wunused-variable]
108 | ll o = 1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
304 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
304 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
300 KB |
Output is correct |
25 |
Correct |
1 ms |
292 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
8124 KB |
Output is correct |
2 |
Correct |
111 ms |
8120 KB |
Output is correct |
3 |
Correct |
105 ms |
8124 KB |
Output is correct |
4 |
Correct |
112 ms |
8148 KB |
Output is correct |
5 |
Correct |
64 ms |
8020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2260 KB |
Output is correct |
2 |
Correct |
28 ms |
2260 KB |
Output is correct |
3 |
Correct |
27 ms |
2260 KB |
Output is correct |
4 |
Correct |
19 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
21 ms |
2488 KB |
Output is correct |
7 |
Correct |
25 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
4220 KB |
Output is correct |
2 |
Correct |
53 ms |
4220 KB |
Output is correct |
3 |
Correct |
99 ms |
8120 KB |
Output is correct |
4 |
Correct |
66 ms |
8020 KB |
Output is correct |
5 |
Correct |
33 ms |
4724 KB |
Output is correct |
6 |
Correct |
59 ms |
8892 KB |
Output is correct |
7 |
Correct |
95 ms |
9600 KB |
Output is correct |
8 |
Correct |
49 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
304 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
300 KB |
Output is correct |
25 |
Correct |
1 ms |
292 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
119 ms |
8124 KB |
Output is correct |
28 |
Correct |
111 ms |
8120 KB |
Output is correct |
29 |
Correct |
105 ms |
8124 KB |
Output is correct |
30 |
Correct |
112 ms |
8148 KB |
Output is correct |
31 |
Correct |
64 ms |
8020 KB |
Output is correct |
32 |
Correct |
34 ms |
2260 KB |
Output is correct |
33 |
Correct |
28 ms |
2260 KB |
Output is correct |
34 |
Correct |
27 ms |
2260 KB |
Output is correct |
35 |
Correct |
19 ms |
2260 KB |
Output is correct |
36 |
Correct |
1 ms |
300 KB |
Output is correct |
37 |
Correct |
21 ms |
2488 KB |
Output is correct |
38 |
Correct |
25 ms |
2644 KB |
Output is correct |
39 |
Correct |
51 ms |
4220 KB |
Output is correct |
40 |
Correct |
53 ms |
4220 KB |
Output is correct |
41 |
Correct |
99 ms |
8120 KB |
Output is correct |
42 |
Correct |
66 ms |
8020 KB |
Output is correct |
43 |
Correct |
33 ms |
4724 KB |
Output is correct |
44 |
Correct |
59 ms |
8892 KB |
Output is correct |
45 |
Correct |
95 ms |
9600 KB |
Output is correct |
46 |
Correct |
49 ms |
5100 KB |
Output is correct |
47 |
Correct |
64 ms |
5180 KB |
Output is correct |
48 |
Correct |
68 ms |
5176 KB |
Output is correct |
49 |
Correct |
110 ms |
10040 KB |
Output is correct |
50 |
Correct |
71 ms |
9264 KB |
Output is correct |
51 |
Correct |
56 ms |
7016 KB |
Output is correct |
52 |
Correct |
80 ms |
9264 KB |
Output is correct |
53 |
Correct |
62 ms |
9388 KB |
Output is correct |
54 |
Correct |
86 ms |
10028 KB |
Output is correct |
55 |
Correct |
101 ms |
10036 KB |
Output is correct |