#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;
cmax(ans, suf[i+1].ff + (int)get_pos(v, suf[i+1].ss + x + 1));
}
cmax(ans, (int)v.size());
printf("%lld", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
7056 KB |
Output is correct |
2 |
Correct |
115 ms |
7056 KB |
Output is correct |
3 |
Correct |
98 ms |
6960 KB |
Output is correct |
4 |
Correct |
114 ms |
6976 KB |
Output is correct |
5 |
Incorrect |
67 ms |
7868 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2092 KB |
Output is correct |
2 |
Correct |
25 ms |
2088 KB |
Output is correct |
3 |
Correct |
26 ms |
2100 KB |
Output is correct |
4 |
Correct |
16 ms |
2428 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
17 ms |
2476 KB |
Output is correct |
7 |
Incorrect |
24 ms |
2096 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
3592 KB |
Output is correct |
2 |
Correct |
52 ms |
3636 KB |
Output is correct |
3 |
Correct |
112 ms |
7048 KB |
Output is correct |
4 |
Correct |
63 ms |
7868 KB |
Output is correct |
5 |
Correct |
33 ms |
4212 KB |
Output is correct |
6 |
Correct |
64 ms |
7592 KB |
Output is correct |
7 |
Correct |
79 ms |
7776 KB |
Output is correct |
8 |
Correct |
47 ms |
3652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |