#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using ll = long long;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll const INF = 1e14;
int ceil_lg(int k)
{
int res = __lg(k);
if (1<<res < k)
res++;
return res;
}
struct SegTree
{
SegTree(int size) : arr(1<<(ceil_lg(size)+1)), lazy(1<<(ceil_lg(size)+1)) {}
void push(int v)
{
arr[2*v] += lazy[v];
arr[2*v+1] += lazy[v];
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
lazy[v] = 0;
}
ll query(int l, int r, int v = 1, int a = 0, int b = -1)
{
if (b == -1)
b = arr.size()/2-1;
if (b < l || a > r)
return LLONG_MIN;
else if (l <= a && b <= r)
return arr[v];
else
{
int mid = (a+b)/2;
push(v);
return max(query(l, r, 2*v, a, mid), query(l, r, 2*v+1, mid+1, b));
}
}
void update(int l, int r, ll val, int v = 1, int a = 0, int b = -1)
{
if (b == -1)
b = arr.size()/2-1;
if (b < l || a > r)
return;
else if (l <= a && b <= r)
{
arr[v] += val;
lazy[v] += val;
}
else
{
int mid = (a+b)/2;
push(v);
update(l, r, val, 2*v, a, mid);
update(l, r, val, 2*v+1, mid+1, b);
arr[v] = max(arr[2*v], arr[2*v+1]);
}
}
vector<ll> arr;
vector<ll> lazy;
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
ll d;
cin >> n >> m >> d;
vector<ll> ans(n+m+1);
vector<pair<ll, int>> a(n+m+1);
for (int i = 1; i <= n+m; i++)
{
cin >> a[i].first;
a[i].second = i;
}
auto a_sort = a;
sort(a_sort.begin(), a_sort.end());
map<pair<ll, int>, int> val_to_idx;
for (int i = 1; i <= n+m; i++)
val_to_idx[a_sort[i]] = i;
SegTree st1(n+m+1), st2(n+m+1);
st1.update(1, n+m, -INF);
st2.update(1, n+m, -INF);
ordered_set<pair<ll, int>> os;
for (int i = 1; i <= n+m; i++)
{
int idx = val_to_idx[a[i]];
ll smaller = os.order_of_key(a[i])+1;
os.insert(a[i]);
st1.update(idx, n+m, -d);
st1.update(idx, idx, INF + a[i].first);
st2.update(idx, n+m, d);
st2.update(idx, idx, INF - a[i].first);
ll q1 = st1.query(1, idx);
ll q2 = st2.query(idx, n+m);
ans[i] = q1 + q2;
}
for (int i = n+1; i <= n+m; i++)
{
cout << ans[i]/2;
if (ans[i] % 2 == 1)
cout << ".5";
cout << ' ';
}
}
| # | 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... |