This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
const int T_MAX = (int) 2e9;
int n, x;
int t[N_MAX + 2];
int before[N_MAX + 2], after[N_MAX + 2];
map <int, int> beforeFen, afterFen;
void update (map <int, int> &Fen, int pos, int val) {
for (ll i = pos; i <= T_MAX; i += i & -i) {
Fen[i] = max(Fen[i], val);
}
}
int query (map <int, int> Fen, int pos) {
int ret = 0;
for (int i = pos; i >= 1; i -= i & -i) {
ret = max(ret, Fen[i]);
}
return ret;
}
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 >> t[i];
}
for (int i = 1; i <= n; i++) {
before[i] = query(beforeFen, t[i] - 1) + 1;
after[i] = max(query(afterFen, t[i] - 1), query(beforeFen, t[i] + x - 1)) + 1;
update(beforeFen, t[i], before[i]);
update(afterFen, t[i], after[i]);
}
cout << query(afterFen, T_MAX) << "\n";
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... |