This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define int ll
const int N = 3e5 + 5;
int n, a[N], d;
const ll inf = 1e18;
ll arr[2][N];
void upd(int t, int l, int r, int val) {
for (int i = l; i <= r; i++)
arr[t][i] = val;
}
int bs(int t, int val) {
for (int i = 1; i < N; i++) {
if (arr[t][i] >= val)
return i;
}
}
int get(int t, int i) {
return arr[t][i];
}
void solve() {
cin >> n >> d;
for (int i = 0; i < n; i++)
cin >> a[i];
fill(arr[1], arr[1] + N, inf);
fill(arr[0], arr[0] + N, inf);
// inx, l, r, val
for (int i = 0; i < n; i++) {
if (i >= d) {
int j = bs(0, i - d);
//cout << "bs " << j << endl;
upd(0, 1, j - 1, get(0, j));
upd(1, 1, j - 1, get(1, j));
}
int j = bs(1, a[i]);
upd(0, j, n, i);
upd(1, j, j, a[i]);
continue;
for (int j = 1; j < n; j++)
cout << arr[1][j] << ' ';
cout << endl;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (get(1, i) < inf) {
ans = i;
}
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'll bs(ll, ll)':
Main.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
23 | }
| ^
# | 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... |