이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 1000000007;
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n, x;
cin >> n >> x;
vl a(n);
for(int i = 0; i < n; i++) cin >> a[i];
vl b(200010, linf);
stack<pair<ll,ll>> undo;
for(int i = n-1; i >= 0; i--){
int p = lower_bound(all(b), -a[i]-x) - b.begin();
undo.emplace(p, b[p]);
b[p] = -a[i]-x;
}
vl c(200010, linf);
int len = 0;
int ans = 0;
for(int i = 0; i < n; i++){
b[undo.top().first] = undo.top().second;
undo.pop();
int p = lower_bound(all(c), a[i]) - c.begin();
if(c[p] == linf) len++;
if(c[p+1] == linf){
assert(p+1 == len);
ans = max(ans, len + (int)(lower_bound(all(b), -a[i]) - b.begin()));
}
c[p] = a[i];
}
cout << ans << "\n";
}
# | 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... |