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 all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int main() {
int n,x; cin >> n >> x;
vi dp,dp2;
while(n--) {
int a; cin >> a;
// dp2 can be made better with a normally
auto it = lower_bound(all(dp2),a);
if(it==dp2.end()) dp2.push_back(a);
else *it=a;
// now make dp2 better with special transition
int j = lower_bound(all(dp),a+x)-dp.begin();
if(j==dp2.size()) dp2.push_back(a);
else dp2[j] = min(dp2[j],a);
// normal transition for dp
it = lower_bound(all(dp),a);
if(it==dp.end()) dp.push_back(a);
else *it=a;
}
cout << dp2.size() << '\n';
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:23:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(j==dp2.size()) dp2.push_back(a);
| ~^~~~~~~~~~~~
# | 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... |