이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
const int M_MAX = 200000;
const int X_MAX = N_MAX + M_MAX;
const ll INF = LLONG_MAX / 2;
int N, M, D;
int A[N_MAX + 2];
int B[M_MAX + 2];
int Aid[N_MAX + 2];
int Bid[M_MAX + 2];
int X;
pair <int, int> aux[X_MAX + 2];
void compress () {
for (int i = 1; i <= N; i++) {
aux[++X] = make_pair(A[i], i);
}
for (int i = 1; i <= M; i++) {
aux[++X] = make_pair(B[i], N + i);
}
sort(aux + 1, aux + X + 1);
for (int i = 1; i <= X; i++) {
if (aux[i].second <= N) {
Aid[aux[i].second] = i;
} else {
Bid[aux[i].second - N] = i;
}
}
}
struct SegInfo {
ll mx, mn;
ll maxDiff;
ll lazy;
SegInfo () {
mx = -INF;
mn = +INF;
maxDiff = 0;
lazy = 0;
}
void init (const int &val) {
mx = mn = val - lazy;
maxDiff = 0;
}
void add (const ll &val) {
mx -= val;
mn -= val;
lazy += val;
}
};
SegInfo operator + (const SegInfo &A, const SegInfo &B) {
SegInfo C;
C.mx = max(A.mx, B.mx);
C.mn = min(A.mn, B.mn);
C.maxDiff = max({A.maxDiff, B.maxDiff, A.mx - B.mn});
C.lazy = 0;
return C;
}
SegInfo segTree[X_MAX * 4 + 2];
void update (int node, int l, int r, int pos, int val) {
if (l == r) {
segTree[node].init(val);
return;
}
int mid = (l + r) / 2;
int left = node * 2, right = node * 2 + 1;
segTree[left].add(segTree[node].lazy);
segTree[right].add(segTree[node].lazy);
if (pos <= mid) {
update(left, l, mid, pos, val);
segTree[right].add(D);
} else {
update(right, mid + 1, r, pos, val);
}
segTree[node] = segTree[left] + segTree[right];
}
void update (int pos, int val) {
update(1, 1, X, pos, val);
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> D;
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
for (int i = 1; i <= M; i++) {
cin >> B[i];
}
compress();
for (int i = 1; i <= N; i++) {
update(Aid[i], A[i]);
}
for (int i = 1; i <= M; i++) {
update(Bid[i], B[i]);
ll t = segTree[1].maxDiff;
if (t % 2 == 0) {
cout << t / 2 << " ";
} else {
cout << t / 2 << ".5 ";
}
}
cout << "\n";
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... |