#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>
#define MEM 1111111
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 1e17+7;
const ll MOD = 998244353;
ll gcd(ll a, ll b){
if(a%b) return gcd(b, a%b);
return b;
}
ll t,n,m,a,b,x;
signed main(){
sanic; cin.tie(0);
cin >> n >> x;
vector<ll> l;
for(int i=0; i<n; i++){
ll q;
cin >> q;
l.pb(q);
}
vector<int> lis,dp(n);
lis.pb(-INF);
for(int i=0; i<n; i++){
if(lis.back()<l[i]){
lis.pb(l[i]);
dp[i] = lis.sz-1;
}
else{
int idx=lower_bound(lis.begin(), lis.end(), l[i])-lis.begin();
lis[idx] = l[i];
dp[i] = idx;
}
}
vector<int> p;
p.pb(-INF);
int ans=0;
for(int i=n-1; i>=0; i--){
int id=lower_bound(p.begin(), p.end(), -l[i]+x)-p.begin();
//cout << dp[i] << ' ' << id-1 << '\n';
ans = max(dp[i]+id-1, ans);
if(p.back()<-l[i])
p.pb(-l[i]);
else{
int idx=lower_bound(p.begin(), p.end(), -l[i])-p.begin();
p[idx] = -l[i];
}
}
cout << ans;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:34:12: warning: overflow in conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '-100000000000000000' to '-1569325056' [-Woverflow]
34 | lis.pb(-INF);
| ^~~~
glo.cpp:47:10: warning: overflow in conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '-100000000000000000' to '-1569325056' [-Woverflow]
47 | p.pb(-INF);
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 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 |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
4520 KB |
Output is correct |
2 |
Correct |
54 ms |
4548 KB |
Output is correct |
3 |
Correct |
53 ms |
4548 KB |
Output is correct |
4 |
Correct |
55 ms |
4508 KB |
Output is correct |
5 |
Correct |
26 ms |
5028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1368 KB |
Output is correct |
2 |
Correct |
13 ms |
1384 KB |
Output is correct |
3 |
Correct |
12 ms |
1368 KB |
Output is correct |
4 |
Correct |
8 ms |
1492 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1492 KB |
Output is correct |
7 |
Correct |
11 ms |
1420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2396 KB |
Output is correct |
2 |
Correct |
23 ms |
2460 KB |
Output is correct |
3 |
Correct |
48 ms |
4608 KB |
Output is correct |
4 |
Correct |
26 ms |
5056 KB |
Output is correct |
5 |
Correct |
13 ms |
2688 KB |
Output is correct |
6 |
Correct |
22 ms |
4956 KB |
Output is correct |
7 |
Correct |
27 ms |
5628 KB |
Output is correct |
8 |
Correct |
19 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 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 |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
53 ms |
4520 KB |
Output is correct |
28 |
Correct |
54 ms |
4548 KB |
Output is correct |
29 |
Correct |
53 ms |
4548 KB |
Output is correct |
30 |
Correct |
55 ms |
4508 KB |
Output is correct |
31 |
Correct |
26 ms |
5028 KB |
Output is correct |
32 |
Correct |
12 ms |
1368 KB |
Output is correct |
33 |
Correct |
13 ms |
1384 KB |
Output is correct |
34 |
Correct |
12 ms |
1368 KB |
Output is correct |
35 |
Correct |
8 ms |
1492 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
7 ms |
1492 KB |
Output is correct |
38 |
Correct |
11 ms |
1420 KB |
Output is correct |
39 |
Correct |
24 ms |
2396 KB |
Output is correct |
40 |
Correct |
23 ms |
2460 KB |
Output is correct |
41 |
Correct |
48 ms |
4608 KB |
Output is correct |
42 |
Correct |
26 ms |
5056 KB |
Output is correct |
43 |
Correct |
13 ms |
2688 KB |
Output is correct |
44 |
Correct |
22 ms |
4956 KB |
Output is correct |
45 |
Correct |
27 ms |
5628 KB |
Output is correct |
46 |
Correct |
19 ms |
2384 KB |
Output is correct |
47 |
Correct |
28 ms |
2432 KB |
Output is correct |
48 |
Correct |
26 ms |
2376 KB |
Output is correct |
49 |
Correct |
54 ms |
4612 KB |
Output is correct |
50 |
Correct |
26 ms |
5076 KB |
Output is correct |
51 |
Correct |
20 ms |
4168 KB |
Output is correct |
52 |
Correct |
27 ms |
5168 KB |
Output is correct |
53 |
Correct |
23 ms |
5188 KB |
Output is correct |
54 |
Correct |
30 ms |
5840 KB |
Output is correct |
55 |
Correct |
44 ms |
4548 KB |
Output is correct |