This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (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... |