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 int long long
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
struct segtree_mss {
struct node {
int premax = 0;
int sufmax = 0;
int totmax = 0;
int sum = 0;
};
vector<node> st;
int stok;
void push_up(int idx) {
st[idx].premax = max(st[2*idx+1].premax, st[2*idx+1].sum + st[2*idx+2].premax);
st[idx].sufmax = max(st[2*idx+2].sufmax, st[2*idx+2].sum + st[2*idx+1].sufmax);
st[idx].totmax = max({
st[2*idx+1].totmax,
st[2*idx+2].totmax,
st[2*idx+1].sufmax + st[2*idx+2].premax
});
st[idx].sum = st[2*idx+1].sum + st[2*idx+2].sum;
}
void u(int l, int r, int tar, int idx, int val) {
if(l == r) {
st[idx].sum = val;
st[idx].premax = max(val, 0ll);
st[idx].sufmax = max(val, 0ll);
st[idx].totmax = max(val, 0ll);
return;
}
int mid = (l + r) >> 1;
if(tar <= mid) u(l, mid, tar, 2*idx+1, val);
else u(mid+1, r, tar, 2*idx+2, val);
push_up(idx);
}
public:
void resize(int k) {
stok = k;
st.resize(4*k + 10);
}
void point_assign(int i, int v) {
u(1, stok, i, 0, v);
}
int query_mss() {
return st[0].totmax;
}
};
void solve(int tc) {
int n, m, d;
cin >> n >> m >> d;
if(n > 0) {
vector<int> v;
for(int i=1; i<=n+m; i++) {
int x;
cin >> x;
v.push_back(x);
if(i <= n) continue;
sort(v.begin(), v.end());
int lb = 0, rb = 1e15;
while(lb < rb) {
double mid = (lb + rb) * 0.25;
double mind = v[0] - mid;
bool ok = 1;
for(int i=1; i<v.size(); i++) {
double res = v[i] - mid;
double new_mind = max(mind + d, res);
if(new_mind - mind < d || abs(new_mind - v[i]) > mid) {
ok = 0; break;
}
mind = new_mind;
}
int realmid = (lb + rb) / 2;
if(ok) rb = realmid;
else lb = realmid + 1;
}
if(lb & 1) cout << lb / 2 << ".5" << " \n"[i == n+m];
else cout << lb / 2 << " \n"[i == n+m];
}
return;
}
int dp[m+1];
dp[0] = 0;
int w[m+1], v[m+1];
pair<int, int> ww[m+1];
int pos[m+1];
for(int i=1; i<=m; i++) {
cin >> w[i];
ww[i].first = w[i];
ww[i].second = i;
}
sort(ww+1, ww+1+m);
for(int i=1; i<=m; i++) pos[ww[i].second] = i;
v[1] = 0;
for(int i=2; i<=m; i++) v[i] = d - (w[i] - w[i-1]);
segtree_mss stm;
stm.resize(m);
set<pair<int, int> > st;
st.insert({4e9, -1});
st.insert({-4e9, -1});
for(int i=1; i<=m; i++) {
if(st.empty()) {
st.insert({w[i], i});
cout << 0 << " \n"[i == m];
continue;
}
auto it = st.lower_bound({w[i], i});
if((*it).second != -1) {
int ptr = (*it).second;
stm.point_assign(pos[ptr], d - ((*it).first - w[i]));
}
it--;
if((*it).second != -1) {
stm.point_assign(pos[i], d - (w[i] - (*it).first));
}
else {
stm.point_assign(pos[i], 0);
}
st.insert({w[i], i});
int ans = stm.query_mss();
cout << ans / 2 << (ans & 1 ? ".5" : "") << " \n"[i == m];
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
/*
>= 0 required
> 2*t: sad
bounding trick? (IOI 2021 candies)
1) point update the array
2) compute the answer given t
-> given many queries
Type 1: (x[i] < 0) a[i]:=max(0, a[i]-x[i])
Type 2: (x[i] >= 0) a[i]:=a[i]+x[i], if a[i] > 2*t then SAD
Basically -> max subarray sum > 2*t: SAD else NOT SAD
*/
Compilation message (stderr)
Main.cpp: In function 'void solve(long long int)':
Main.cpp:85:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=1; i<v.size(); i++) {
| ~^~~~~~~~~
Main.cpp:102:7: warning: variable 'dp' set but not used [-Wunused-but-set-variable]
102 | int dp[m+1];
| ^~
Main.cpp:104:15: warning: variable 'v' set but not used [-Wunused-but-set-variable]
104 | int w[m+1], v[m+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... |