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 <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second
const int maxn = 200001, k = 18;
int n;
pi a[maxn];
int b[maxn], lg[maxn];
int st[2][k][maxn];
int ans[maxn];
int mx(int t, int l, int r){
if(l > r) return 0;
int z = lg[r - l + 1];
return max(st[t][z][l], st[t][z][r - (1 << z) + 1]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i <= n; i++){
cin >> a[i].f;
a[i].s = i;
}
for(int i = 0; i < n; i++) cin >> b[i];
sort(a, a + n + 1);
sort(b, b + n);
for(int i = 0; i < n; i++){
st[0][0][i] = max(a[i].f - b[i], 0);
st[1][0][i] = max(a[i + 1].f - b[i], 0);
}
for(int t = 0; t < 2; t++)
for(int i = 1; i < k; i++)
for(int j = 0; j + (1 << i) <= n; j++){
st[t][i][j] = max(st[t][i - 1][j], st[t][i - 1][j + (1 << (i - 1))]);
}
lg[1] = 0;
for(int i = 2; i <= n; i++) lg[i] = lg[i - 1] + (1 << (lg[i - 1] + 1) == i);
for(int i = 0; i <= n; i++){
ans[a[i].s] = max(mx(0, 0, i - 1), mx(1, i, n - 1));
}
cout << ans[0];
for(int i = 1; i <= n; i++) cout << " " << ans[i];
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... |