#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
#define debug(x) (cerr << (#x) << " = " << x << "\n")
#define cmax(a,b) (a = max(a,b))
#define cmin(a,b) (a = min(a,b))
template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
int n,x;
cin >> n >> x;
int arr[n];
int rev[n];
F(n) cin >> arr[i];
F(n) rev[i] = -arr[n-1-i];
int ans = 0;
pii suf[n]; // (length, greatest)
vector<int> v;
F(n){
int c = get_pos(v, rev[i]);
if(c == (int)v.size()){
v.pb(rev[i]);
}else{
cmin(v[c], rev[i]);
}
suf[n-1-i] = mp((int)v.size(), -v.back());
}
//F(n) printf("%d %d\n", suf[i].ff, suf[i].ss);
v.clear();
F(n){
int c = get_pos(v, arr[i]);
if( c == (int) v.size()){
v.pb(arr[i]);
}else{
cmin(v[c], arr[i]);
}
if(i == n-1) break;
int bruh = get_pos(v, suf[i+1].ss + x - 1);
cmax(ans, suf[i+1].ff + bruh);
}
cmax(ans, (int)v.size());
printf("%lld", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
6476 KB |
Output is correct |
2 |
Correct |
96 ms |
6484 KB |
Output is correct |
3 |
Correct |
102 ms |
6472 KB |
Output is correct |
4 |
Correct |
100 ms |
6472 KB |
Output is correct |
5 |
Correct |
64 ms |
7628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1836 KB |
Output is correct |
2 |
Correct |
24 ms |
1828 KB |
Output is correct |
3 |
Correct |
25 ms |
1844 KB |
Output is correct |
4 |
Correct |
15 ms |
2188 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
16 ms |
2228 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
3504 KB |
Output is correct |
2 |
Correct |
49 ms |
3380 KB |
Output is correct |
3 |
Correct |
96 ms |
6468 KB |
Output is correct |
4 |
Correct |
63 ms |
7612 KB |
Output is correct |
5 |
Correct |
31 ms |
3928 KB |
Output is correct |
6 |
Correct |
60 ms |
7344 KB |
Output is correct |
7 |
Correct |
87 ms |
7328 KB |
Output is correct |
8 |
Correct |
45 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
296 KB |
Output is correct |
7 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |