이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <bitset>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int inf = 1e9 + 100;
const int maxn = 2e5 + 100;
int fen[2][2 * maxn];
int dp[maxn][2], a[maxn];
void change (int idx, int val1, int val2) {
for (; idx < 2 * maxn; idx += idx & -idx) {
fen[0][idx] = max (fen[0][idx], val1);
fen[1][idx] = max (fen[1][idx], val2);
}
}
int get (int idx, bool wh) {
int ret = 0;
for (; idx > 0; idx -= idx & -idx)
ret = max (ret, fen[wh][idx]);
return ret;
}
int n, x;
int nex[2 * maxn];
vector <int> v;
void compress () {
for (int i = 0; i < n; i++) {
v.PB (a[i]);
v.PB (a[i] + x);
}
sort (v.begin(), v.end());
v.resize (unique (v.begin(), v.end()) - v.begin());
for (int i = 0; i < n; i++) {
int tmp = a[i];
a[i] = lower_bound (v.begin(), v.end(), a[i]) - v.begin() + 1;
nex[a[i]] = lower_bound (v.begin(), v.end(), tmp + x) - v.begin() + 1;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> x;
for (int i = 0; i < n; i++)
cin >> a[i];
compress ();
dp[0][0] = 1;
dp[0][1] = 1;
int ans = 1;
change (a[0], dp[0][0], dp[0][1]);
for (int i = 1; i < n; i++) {
dp[i][0] = get (a[i] - 1, 0) + 1;
dp[i][1] = get (nex[a[i]] - 1, 0) + 1;
dp[i][1] = max (dp[i][1], get (a[i] - 1, 1) + 1);
change (a[i], dp[i][0], dp[i][1]);
ans = max (ans, dp[i][1]);
}
cout << ans << endl;
}
# | 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... |