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 ar array
#define int long long
const int inf = 1e9 + 5;
const int N = 1e5 + 5;
struct ST{
int mn[N<<2], mx[N<<2];
void sett(int i, int v, int lx = 0, int rx = N, int x = 1){
if(lx == rx) { mn[x] = mx[x] = v; return; }
int m = (lx + rx) >> 1;
if(i <= m) sett(i, v, lx, m, x<<1);
else sett(i, v, m+1, rx, x<<1|1);
mn[x] = min(mn[x<<1], mn[x<<1|1]);
mx[x] = max(mx[x<<1], mx[x<<1|1]);
}
int get_rm_low(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return -1;
if(lx >= l && rx <= r){
if(mn[x] > v) return -1;
if(lx == rx) return lx;
int m = (lx + rx) >> 1;
if(mn[x<<1|1] <= v) return get_rm_low(l, r, v, m+1, rx, x<<1|1);
return get_rm_low(l, r, v, lx, m, x<<1);
} int m = (lx + rx) >> 1;
int res = get_rm_low(l, r, v, m+1, rx, x<<1|1);
if(~res) return res;
return get_rm_low(l, r, v, lx, m, x<<1);
}
int get_lm_big(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return -1;
if(lx >= l && rx <= r){
if(mx[x] < v) return -1;
if(lx == rx) return lx;
int m = (lx + rx) >> 1;
if(mx[x<<1] >= v) return get_lm_big(l, r, v, lx, m, x<<1);
return get_lm_big(l, r, v, m+1, rx, x<<1|1);
} int m = (lx + rx) >> 1;
int res = get_lm_big(l, r, v, lx, m, x<<1);
if(~res) return res;
return get_lm_big(l, r, v, m+1, rx, x<<1|1);
}
}tree;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, k, t; cin>>n>>k>>t;
vector<int> a(n), d(n);
for(int i=0;i<n;i++) cin>>a[i], a[i] *= 2;
for(int i=1;i<n;i++){
d[i] = a[i] - a[i-1];
}
k--;
auto check = [&](int s){
vector<int> b(n);
for(int i=0;i<n;i++) b[i] = a[i] / 2 - i * s * t, tree.sett(i, b[i]);
int pos = tree.get_lm_big(k, n-1, b[k] + 1);
if(pos == -1) pos = n;
pos--;
for(int i=k;i>0;i--){
if(b[i-1] >= b[i]){
pos = tree.get_lm_big(pos, n-1, b[i-1] + 1);
if(pos == -1) pos = n;
pos--;
} else {
pos = tree.get_rm_low(k, pos, b[i-1]);
if(pos == -1){
return false;
}
}
}
return (pos == n - 1);
};
int l = 0, r = 2 * inf;
while(l < r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
cout<<(l+1) / 2<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |