This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
 
using namespace std;
 
const int N = 2e5+5;
int a[N], b[N], n;
int ft[2][2 * N];
 
void update(int i, int x, int val)
{
  while(x < 2 * N)
    {
      ft[i][x] = max(ft[i][x], val);
      x += (x & (-x));
    }
}
int query(int i, int x)
{
  int ans = 0;
  while(x > 0)
    {
      ans = max(ans, ft[i][x]);
      x -= (x & (-x));
    }
  return ans;
}
 
int compute()
{
  vector<int> v;
  for(int i = 0; i < n; i ++)
    v.push_back(b[i]), v.push_back(a[i]);
 
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
 
  for(int i = 0; i < n; i ++)
    b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin() + 1;
 
  for(int i = 0; i < n; i ++)
    a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
  
  int ans = 1;
  for(int i = 0; i < n; i ++)
    {
      int x = query(1, a[i] - 1) + 1;
      ans = max(x, ans);
 
      int y = query(0, a[i] - 1) + 1;
      ans = max(y, ans);
      update(0, a[i], y);
      
      update(1, a[i], x);
      update(1, b[i], y);
    }
  return ans;
}
 
int main()
{
  int x;
  cin >> n >> x;
  for(int i = 0; i < n; i ++)
    {
      cin >> a[i];
      b[i] = a[i] - x;
    }
  cout << compute() << endl;
  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... |