#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC optimize("Ofast,unroll-loops,inline-functions,no-stack-protector,03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma clang loop vectorize(enable)
#pragma clang loop interleave(enable)
#endif
#define int long long
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define nl '\n'
#define o_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;
void file( string s = "" )
{
if( s.empty() )
return;
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int N = 2e5 + 2;
const int N1 = 1e6 + 2;
const int inf = 1e9 + 2;
const int INF = 1e18 + 2;
const int mod = 1e9 + 7;
int T = 1;
void solve()
{
int n;
cin >>n;
int b[n + 1];
array<int, 3> a[n + 2];
set< array<int, 3> > st;
for( int i = 1; i <= n + 1; ++i )
{
cin >>a[i][0];
a[i][1] = i;
a[i][2] = 0;
}
for( int i = 1; i <= n; ++i )
cin >>b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
for( int i = 1; i <= n + 1; ++i )
{
a[i][2] = i;
st.insert(a[i]);
}
int cur = 0;
vector< int > us(n + 1);
for( int i = 1; i <= n; ++i )
{
auto j = st.lower_bound({b[i], 0, 0});
array<int, 3> k1, k2;
k1 = k2 = {INF, 0};
if( j != st.end() )
k1 = *j;
if( j != st.begin() )
k2 = *prev(j);
int x1 = abs(k1[0] - b[i]);
int x2 = abs(k2[0] - b[i]);
if( x1 <= x2 )
{
st.erase(j);
us[k1[2]] = b[i];
cur = max(cur, x1);
}
else
{
st.erase(prev(j));
us[k2[2]] = b[i];
cur = max(cur, x2);
}
}
int pos;
for( int i = 1; i <= n + 1; ++i )
if( !us[i] )
{
pos = i;
break;
}
int ans[n + 1];
vector< int > s(n + 3), p(n + 3), p1(n + 3), s1(n + 3);
for( int i = pos - 1; i >= 1; --i )
s[i] = max(s[i + 1], abs(a[i + 1][0] - us[i]));
for( int i = 1; i < pos; ++i )
p1[i] = max(p1[i - 1], abs(a[i][0] - us[i]));
for( int i = pos + 1; i <= n + 1; ++i )
p[i] = max(p[i - 1], abs(a[i - 1][0] - us[i]));
for( int i = n + 1; i > pos; --i )
s1[i] = max(s1[i + 1], abs(a[i][0] - us[i]));
for( int i = 1; i <= n + 1; ++i )
{
int mx = 0;
if( i < pos )
mx = max({p1[i - 1], s[i], s1[pos + 1]});
if( i > pos )
mx = max({s1[i + 1], p[i], p1[pos - 1]});
if( i == pos )
mx = cur;
ans[a[i][1]] = mx;
}
for( int i = 1; i <= n + 1; ++i )
cout <<ans[i] <<' ';
}
signed main()
{
file("");
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// cin >>T;
while( T-- )
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t1.cpp: In function 'void file(std::string)':
ho_t1.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |