This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Arayi
#include <bits/stdc++.h>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;
lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = {'a', 'e', 'i', 'o', 'u'};
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1, 0};
int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1, 0};
char dc[] = {'R', 'D', 'L', 'U'};
const int N = 5e5 + 20;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const ld e = 1e-13;
const int T = 128;
lli bp(lli a, lli b = mod - 2LL)
{
lli ret = 1;
while (b)
{
if (b & 1)
ret *= a, ret %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ret;
}
ostream &operator<<(ostream &c, pir a)
{
c << a.fr << " " << a.sc;
return c;
}
template <class T>
void maxi(T &a, T b)
{
a = max(a, b);
}
template <class T>
void mini(T &a, T b)
{
a = min(a, b);
}
int n, m;
lli x[N];
lli sum, d;
lli fl[4 * N], t[4 * N], t1[4 * N];
void push(int nd)
{
fl[nd * 2] += fl[nd];
fl[nd * 2 + 1] += fl[nd];
t[nd] += fl[nd];
t1[nd] += fl[nd];
fl[nd] = 0;
}
void upd(int l, int r, lli v, int nl = 0, int nr = n + m + 1, int nd = 1)
{
push(nd);
if (l > nr || r < nl)
return;
if (l == nl && r == nr)
{
fl[nd] += v;
push(nd);
return;
}
int md = (nl + nr) / 2;
upd(l, min(md, r), v, nl, md, nd * 2);
upd(max(md + 1, l), r, v, md + 1, nr, nd * 2 + 1);
t[nd] = min(t[nd * 2], t[nd * 2 + 1]);
t1[nd] = max(t1[nd * 2], t1[nd * 2 + 1]);
}
lli qry(int l, int r, bool b, int nl = 0, int nr = n + m + 1, int nd = 1)
{
push(nd);
if (l > nr || r < nl)
{
if (b)
return LLONG_MAX;
else
return LLONG_MIN;
}
if (l == nl && r == nr)
{
if (b)
return t[nd];
return t1[nd];
}
int md = (nl + nr) / 2;
if (b)
return min(qry(l, min(md, r), b, nl, md, nd * 2), qry(max(md + 1, l), r, b, md + 1, nr, nd * 2 + 1));
return max(qry(l, min(md, r), b, nl, md, nd * 2), qry(max(md + 1, l), r, b, md + 1, nr, nd * 2 + 1));
}
int main()
{
fastio;
//freopen("input.in", "r", stdin);
cin >> n >> m >> d;
vector<pair<lli, int>> fp;
for (int i = 1; i <= n; i++)
{
cin >> x[i];
fp.ad(MP(x[i], i));
}
for (int i = n + 1; i <= n + m; i++)
{
cin >> x[i];
fp.ad(MP(x[i], i));
}
sort(all(fp));
set<int> st;
for (int i = 1; i <= n; i++)
{
int i1 = upper_bound(all(fp), MP(x[i], i)) - fp.begin() - 1;
auto p = st.upper_bound(i1);
// cout << i1 << "-";
if (p != st.end() && p != st.begin())
{
int hj = *p;
int nx = *(--p);
upd(i1 + 1, n + m + 1, d - (fp[hj].fr - x[i]));
upd(nx + 1, n + m + 1, d - (x[i] - fp[nx].fr));
upd(nx + 1, n + m + 1, -d + fp[hj].fr - fp[nx].fr);
// cout << nx << " " << fp[nx].fr << endl;
// cout << hj << " " << fp[hj].fr << endl;
}
else if (p != st.end())
{
int hj = *p;
upd(i1 + 1, n + m + 1, d - (fp[hj].fr - x[i]));
// cout << hj << " " << fp[hj].fr << endl;
}
else if (p != st.begin())
{
int nx = *(--p);
upd(nx + 1, n + m + 1, d - (x[i] - fp[nx].fr));
// cout << nx << " " << fp[nx].fr << endl;
}
maxi(sum, qry(i1, n + m + 1, 0) - qry(0, i1, 1));
st.insert(i1);
// cout << endl;
}
// cout << qry(0, 0, 0) << " " << qry(1, 1, 0) << " " << qry(2, 2, 0) << " " << qry(3, 3, 0) << " " << qry(4, 4, 0) << endl;
for (int i = n + 1; i <= n + m; i++)
{
int i1 = upper_bound(all(fp), MP(x[i], i)) - fp.begin() - 1;
auto p = st.upper_bound(i1);
// cout << i1 << "-";
if (p != st.end() && p != st.begin())
{
int hj = *p;
int nx = *(--p);
upd(i1 + 1, n + m + 1, d - (fp[hj].fr - x[i]));
upd(nx + 1, n + m + 1, d - (x[i] - fp[nx].fr));
upd(nx + 1, n + m + 1, -d + fp[hj].fr - fp[nx].fr);
// cout << nx << " " << fp[nx].fr << endl;
// cout << hj << " " << fp[hj].fr << endl;
}
else if (p != st.end())
{
int hj = *p;
upd(i1 + 1, n + m + 1, d - (fp[hj].fr - x[i]));
// cout << hj << " " << fp[hj].fr << endl;
}
else if (p != st.begin())
{
int nx = *(--p);
upd(nx + 1, n + m + 1, d - (x[i] - fp[nx].fr));
// cout << nx << " " << fp[nx].fr << endl;
}
maxi(sum, qry(i1, n + m + 1, 0) - qry(0, i1, 1));
st.insert(i1);
if (sum % 2LL == 0)
cout << sum / 2LL << " ";
else
cout << sum / 2LL << ".5 ";
}
// cout << qry(0, 0, 0) << " " << qry(1, 1, 0) << " " << qry(2, 2, 0) << " " << qry(3, 3, 0) << " " << qry(4, 4, 0) << endl;
cout << endl;
return 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... |