이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
____ ____ ____ ____ ____
||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 u[N_MAX + 2];
int before[N_MAX + 2], after[N_MAX + 2];
int beforeFen[N_MAX * 2 + 2], afterFen[N_MAX * 2 + 2];
void update (int Fen[], int pos, int val) {
for (int i = pos; i <= n * 2; i += i & -i) {
Fen[i] = max(Fen[i], val);
}
}
int query (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];
u[i] = t[i] + x;
}
map <int, int> mp;
for (int i = 1; i <= n; i++) {
mp[t[i]]; mp[u[i]];
}
int curr = 0;
for (pair <int, int> _ : mp) {
mp[_.first] = ++curr;
}
for (int i = 1; i <= n; i++) {
t[i] = mp[t[i]];
u[i] = mp[u[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, u[i] - 1)) + 1;
update(beforeFen, t[i], before[i]);
update(afterFen, t[i], after[i]);
}
cout << query(afterFen, n * 2) << "\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... |