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>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
struct BIT {
int n;
vector<int> tree;
void config(int _n) {
n = _n + 10;
tree.resize(_n+60);
}
void update(int p, int v) {
for(p++; p<n; p+=p&-p) tree[p] = max(tree[p], v);
}
int query(int p) {
int ans = 0;
for(p++; p>0; p-=p&-p) ans = max(ans, tree[p]);
return ans;
}
void clear() { for(int i=0; i<tree.size(); i++) tree[i] = 0; }
};
int32_t main() {
int n, X, ans = 0;
cin >> n >> X;
set<int> s;
vector<int> v(n+1);
for(int i=1; i<=n; i++) {
cin >> v[i];
s.insert(v[i]); s.insert(v[i] - X);
}
vector<int> comp(all(s));
BIT bit;
bit.config(2*n);
for(int i=0; i<=n; i++) {
v[i] -= X;
for(int i=1; i<=n; i++) {
int p = lower_bound(all(comp), v[i]) - comp.begin();
bit.update(p, bit.query(p-1) + 1);
}
ans = max(ans, bit.query(2*n));
bit.clear();
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
glo.cpp: In member function 'void BIT::clear()':
glo.cpp:40:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | void clear() { for(int i=0; i<tree.size(); i++) tree[i] = 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... |