이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int MAXN = 2e5 + 105;
typedef pair <int, int> ii;
int n, x;
int a[2 * MAXN + 10];
ii b[2 * MAXN + 10];
namespace Sub1
{
    int lis[MAXN + 5];
    void Solve()
    {
        int len = 0;
        for (int i = 1; i <= n; ++i)
        {
            int idx = lower_bound(lis + 1, lis + len + 1, a[i]) - lis;
            lis[idx] = a[i];
            len = max(len, idx);
        }
        cout << len;
    }
}
namespace Sub2
{
    int bitMax[2][2 * MAXN + 10];
    void Update(int bitMax[], int idx, int val)
    {
        for (int i = idx; i <= 2 * n; i += i & (-i))
            bitMax[i] = max(bitMax[i], val);
    }
    int getMax(int bitMax[], int idx)
    {
        int ans = 0;
        for (int i = idx; 0 < i; i -= i & (-i))
            ans = max(ans, bitMax[i]);
        return ans;
    }
    void Solve()
    {
        for (int i = 1; i <= n; ++i)
        {
            cin >> a[i];
            b[i].F = a[i]; b[i].S = i;
            b[n + i].F = a[i] + x, b[n + i].S = n + i;
        }
        sort(b + 1, b + 2 * n + 1);
        for (int i = 1; i <= 2 * n; ++i)
        {
            a[b[i].S] = a[b[i - 1].S] + (b[i - 1].F < b[i].F);
        }
        int res = 0;
        for (int i = 1; i <= n; ++i)
        {
            int val1 = getMax(bitMax[0], a[i] - 1) + 1;
            int val2 = getMax(bitMax[0], a[n + i] - 1) + 1;
            int val3 = getMax(bitMax[1], a[i] - 1) + 1;
            Update(bitMax[0], a[i], val1);
            Update(bitMax[1], a[i], max(val2, val3));
            res = max(max(res, val1), max(val2, val3));
        }
        cout << res;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> x;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    if (x == 0) Sub1::Solve(); else Sub2::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... |