이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};
const int MAX = 200200;
int n, x;
int a[MAX];
int L[MAX];
int ans = 0;
vector<int> dp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> x;
for (int i = 1; i <= n; ++i) cin >> a[i];
dp.clear();
for (int i = 1; i <= n; ++i) {
int pos = lower_bound(all(dp), a[i]) - dp.begin();
if (pos == dp.size()) dp.push_back(a[i]);
else dp[pos] = a[i]; L[i] = pos + 1;
maximize(ans, L[i]); cout << L[i] << ' ';
}
dp.clear();
for (int i = n; i >= 1; --i) {
int POS = lower_bound(all(dp), -a[i] + x) - dp.begin();
maximize(ans, L[i] + POS);
int pos = lower_bound(all(dp), -a[i]) - dp.begin();
if (pos == dp.size()) dp.push_back(-a[i]);
else dp[pos] = -a[i];
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (pos == dp.size()) dp.push_back(a[i]);
| ~~~~^~~~~~~~~~~~
glo.cpp:44:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
44 | else dp[pos] = a[i]; L[i] = pos + 1;
| ^~~~
glo.cpp:44:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
44 | else dp[pos] = a[i]; L[i] = pos + 1;
| ^
glo.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if (pos == dp.size()) dp.push_back(-a[i]);
| ~~~~^~~~~~~~~~~~
glo.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |