이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
const int MAX = 2e5 + 10;
int n, k;
int x, y;
int ucit[MAX];
int arr[MAX];
int treeFront[4 * MAX];
int treeBack[4 * MAX];
int dpFront[MAX];
int dpBack[MAX];
vector <int> v;
map <int, int> mp;
int id;
void updateFront(int left, int right, int a, int idx, int val) {
if (left > a || a > right) return;
if (left == right) {
treeFront[idx] = max(treeFront[idx], val);
return;
}
int mid = (left + right) / 2;
updateFront(left, mid, a, idx * 2, val);
updateFront(mid + 1, right, a, idx * 2 + 1, val);
treeFront[idx] = max(treeFront[idx * 2], treeFront[idx * 2 + 1]);
}
void updateBack(int left, int right, int a, int idx, int val) {
if (left > a || a > right) return;
if (left == right) {
treeBack[idx] = max(treeBack[idx], val);
return;
}
int mid = (left + right) / 2;
updateBack(left, mid, a, idx * 2, val);
updateBack(mid + 1, right, a, idx * 2 + 1, val);
treeBack[idx] = max(treeBack[idx * 2], treeBack[idx * 2 + 1]);
}
int queryFront(int left, int right, int a, int idx) {
if (left > a) return 0;
if (a >= right) {
return treeFront[idx];
}
int mid = (left + right) / 2;
int ret1 = queryFront(left, mid, a, idx * 2);
int ret2 = queryFront(mid + 1, right, a, idx * 2 + 1);
return max(ret1, ret2);
}
int queryBack(int left, int right, int a, int idx) {
if (right < a) return 0;
if (a <= left) {
return treeBack[idx];
}
int mid = (left + right) / 2;
int ret1 = queryBack(left, mid, a, idx * 2);
int ret2 = queryBack(mid + 1, right, a, idx * 2 + 1);
return max(ret1, ret2);
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> ucit[i];
v.push_back(ucit[i]);
v.push_back(ucit[i] + k);
}
sort(v.begin(), v.end());
mp[v[0]] = 0;
id = 1;
for (int i = 1; i < v.size(); i++) {
if (v[i] == v[i - 1]) continue;
mp[v[i]] = id;
id++;
}
for (int i = 1; i <= n; i++) {
arr[i] = mp[ucit[i]];
}
for (int i = n; i >= 1; i--) {
x = arr[i];
dpBack[i] = queryBack(0, n - 1, x + 1, 1) + 1;
updateBack(0, n - 1, x, 1, dpBack[i]);
}
int sol = queryBack(0, n - 1, -1, 1);
for (int i = 1; i < n; i++) {
x = arr[i];
y = arr[i + 1];
dpFront[i] = queryFront(0, n - 1, x - 1, 1) + 1;
updateFront(0, n - 1, x, 1, dpFront[i]);
sol = max(sol, queryFront(0, n - 1, mp[ucit[i + 1] + k] + 1 , 1) + dpBack[i + 1]);
}
sol = max(sol, queryFront(0, n - 1, id, 1));
cout << sol << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 1; i < v.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |