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;
using ll = long long;
#define all(x) x.begin(), x.end()
const int N = 3e5;
int tr[2 * N];
void upd(int k, int x) {
for (tr[k += N] = max(tr[k], x); k; k >>= 1, tr[k] = max(tr[k << 1], tr[k << 1 | 1]));
}
int get(int l, int r) {
l = max(l, 0);
int res = 0;
for (l += N, r += N; l <= r; l >>= 1, r >>= 1) {
if (l & 1) res = max(res, tr[l++]);
if (~r & 1) res = max(res, tr[r--]);
}
return res;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, d;
cin >> n >> d;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].first;
a[i].second = -i;
}
sort(a.begin(), a.end());
for (auto [x, id] : a) {
id = -id;
upd(id, get(id - d, id - 1) + 1);
}
cout << get(0, n - 1);
}
Compilation message (stderr)
Main.cpp: In function 'void upd(int, int)':
Main.cpp:13:15: warning: operation on 'k' may be undefined [-Wsequence-point]
13 | for (tr[k += N] = max(tr[k], x); k; k >>= 1, tr[k] = max(tr[k << 1], tr[k << 1 | 1]));
| ~~^~~~
# | 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... |