This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 4e5 + 1;
int tr[maxn * 4], x, xl, xr;
int get(int v, int l, int r){
if(xl <= l && r <= xr)return tr[v];
if(r <= xl || xr <= l)return 0;
return max(get(v * 2 + 1, l, (l + r) / 2), get(v * 2 + 2, (l + r) / 2, r));
}
void upd(int v, int l, int r){
if(l + 1 == r){
tr[v] = x;
return;
}
if((l + r) / 2 <= xl)upd(v * 2 + 2, (l + r) / 2, r);
else upd(v * 2 + 1, l, (l + r) / 2);
tr[v] = max(tr[v * 2 + 1], tr[v * 2 + 2]);
}
void solve() {
int n;
cin >> n >> x;
int t[n], p[n], sf[n];
set<int> s;
map<int, int> m;
for(int i = 0; i < n; i++){
cin >> t[i];
p[i] = t[i] + x;
s.insert(t[i]);
s.insert(t[i] + x);
}
int cnt = 0;
for(auto i : s)m[i] = cnt++;
for(int i = n - 1; i >= 0; i--){
t[i] = m[t[i]];
p[i] = m[p[i]];
xl = t[i] + 1, xr = maxn;
x = get(0, 0, maxn) + 1;
xl = t[i];
sf[i] = x;
upd(0, 0, maxn);
}
memset(tr, 0, sizeof tr);
int ans = 0;
for(int i = 0; i < n; i++){
xl = 0, xr = p[i];
x = get(0, 0, maxn) + sf[i];
ans = max(ans, x);
xl = 0, xr = t[i];
x = get(0, 0, maxn) + 1;
xl = t[i];
upd(0, 0, maxn);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |