// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e9;
const int mod=998244353;
const int maxn=300005;
const int B=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
const int base=101;
void solve(){
int N;cin >> N;
vector<int> A(2*N),B(N),C(N);
for(int i=0;i<2*N;i++) cin >> A[i];
for(int i=0;i<N;i++) cin >> B[i];
for(int i=0;i<N;i++) cin >> C[i];
sort(B.begin(),B.end());
sort(C.begin(),C.end());
vector<int> A2=A,B2=B,C2=C;
for(int i=0;i<2*N;i++) A2[i]=-A[i];
for(int i=0;i<N;i++) B2[i]=-B2[i],C2[i]=-C2[i];
rotate(A2.begin(),A2.begin()+N,A2.end());
reverse(B2.begin(),B2.end());
reverse(C2.begin(),C2.end());
auto check = [&](int d){
auto get = [&](vector<int> &a,vector<int> &b){
vector<int> cnt(N+1);
{
int pl=0,pr=0,sr=2*N;
for(int i=0;i<N;i++){
while(pl<N && b[pl]<a[i]-d) pl++;
while(pr<N && b[pr]<=a[i]+d) pr++;
while(sr>N && a[sr-1]<a[i]) sr--;
int val=N+i-sr;
if(pr<=val) continue;
int l=max(0,i-pr+1);
int r=(pl<=val?i+1:i-pl+1);
if(l<r) cnt[l]++,cnt[r]--;
}
}
{
int pl=0,pr=0,sr=0;
for(int i=2*N-1;i>=N;i--){
while(pl<N && b[pl]<a[i]-d) pl++;
while(pr<N && b[pr]<=a[i]+d) pr++;
while(sr<N && a[sr]<=a[i]) sr++;
int val=sr-(i-N+1);
if(pr<=val) continue;
int r=min(N,i-N+pr+1);
int l=(pl<=val?i-N+1:i-N+1+pl);
if(l<r) cnt[l]++,cnt[r]--;
}
}
for(int i=1;i<=N;i++) cnt[i]+=cnt[i-1];
for(int i=0;i<N;i++) cnt[i]=(cnt[i]==N);
return cnt;
};
vector<int> X=get(A,B),Y=get(A,C);
vector<int> X2=get(A2,B2),Y2=get(A2,C2);
for(int i=0;i<N;i++){
if(X[i] && Y2[i]) return true;
if(X2[i] && Y[i]) return true;
}
return false;
};
int l=0,r=inf,res=inf;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) res=mid,r=mid-1;
else l=mid+1;
}
cout << res << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
428 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
428 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
604 KB |
Output is correct |
27 |
Correct |
7 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
10 ms |
604 KB |
Output is correct |
31 |
Correct |
10 ms |
860 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
6 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
600 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1034 ms |
26132 KB |
Output is correct |
2 |
Correct |
830 ms |
22652 KB |
Output is correct |
3 |
Correct |
678 ms |
19032 KB |
Output is correct |
4 |
Correct |
1048 ms |
26156 KB |
Output is correct |
5 |
Correct |
848 ms |
22640 KB |
Output is correct |
6 |
Correct |
24 ms |
1152 KB |
Output is correct |
7 |
Correct |
494 ms |
26960 KB |
Output is correct |
8 |
Correct |
467 ms |
21684 KB |
Output is correct |
9 |
Correct |
848 ms |
26176 KB |
Output is correct |
10 |
Correct |
978 ms |
26168 KB |
Output is correct |
11 |
Correct |
977 ms |
26164 KB |
Output is correct |
12 |
Correct |
923 ms |
23832 KB |
Output is correct |
13 |
Correct |
792 ms |
22660 KB |
Output is correct |
14 |
Correct |
491 ms |
26340 KB |
Output is correct |
15 |
Correct |
474 ms |
22628 KB |
Output is correct |
16 |
Correct |
460 ms |
22656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
428 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
604 KB |
Output is correct |
27 |
Correct |
7 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
10 ms |
604 KB |
Output is correct |
31 |
Correct |
10 ms |
860 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
8 ms |
604 KB |
Output is correct |
35 |
Correct |
6 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
600 KB |
Output is correct |
38 |
Correct |
4 ms |
604 KB |
Output is correct |
39 |
Correct |
4 ms |
604 KB |
Output is correct |
40 |
Correct |
3 ms |
348 KB |
Output is correct |
41 |
Correct |
1034 ms |
26132 KB |
Output is correct |
42 |
Correct |
830 ms |
22652 KB |
Output is correct |
43 |
Correct |
678 ms |
19032 KB |
Output is correct |
44 |
Correct |
1048 ms |
26156 KB |
Output is correct |
45 |
Correct |
848 ms |
22640 KB |
Output is correct |
46 |
Correct |
24 ms |
1152 KB |
Output is correct |
47 |
Correct |
494 ms |
26960 KB |
Output is correct |
48 |
Correct |
467 ms |
21684 KB |
Output is correct |
49 |
Correct |
848 ms |
26176 KB |
Output is correct |
50 |
Correct |
978 ms |
26168 KB |
Output is correct |
51 |
Correct |
977 ms |
26164 KB |
Output is correct |
52 |
Correct |
923 ms |
23832 KB |
Output is correct |
53 |
Correct |
792 ms |
22660 KB |
Output is correct |
54 |
Correct |
491 ms |
26340 KB |
Output is correct |
55 |
Correct |
474 ms |
22628 KB |
Output is correct |
56 |
Correct |
460 ms |
22656 KB |
Output is correct |
57 |
Correct |
1161 ms |
25996 KB |
Output is correct |
58 |
Correct |
1325 ms |
22692 KB |
Output is correct |
59 |
Correct |
392 ms |
17068 KB |
Output is correct |
60 |
Correct |
1681 ms |
26288 KB |
Output is correct |
61 |
Correct |
1379 ms |
22756 KB |
Output is correct |
62 |
Correct |
443 ms |
19248 KB |
Output is correct |
63 |
Correct |
16 ms |
1068 KB |
Output is correct |
64 |
Correct |
1083 ms |
26796 KB |
Output is correct |
65 |
Correct |
1035 ms |
21592 KB |
Output is correct |
66 |
Correct |
1621 ms |
26280 KB |
Output is correct |
67 |
Correct |
510 ms |
26296 KB |
Output is correct |
68 |
Correct |
517 ms |
26304 KB |
Output is correct |
69 |
Correct |
334 ms |
17708 KB |
Output is correct |
70 |
Correct |
493 ms |
26304 KB |
Output is correct |
71 |
Correct |
441 ms |
26292 KB |
Output is correct |
72 |
Correct |
543 ms |
26524 KB |
Output is correct |
73 |
Correct |
544 ms |
26464 KB |
Output is correct |
74 |
Correct |
1066 ms |
26228 KB |
Output is correct |
75 |
Correct |
701 ms |
17600 KB |
Output is correct |
76 |
Correct |
1048 ms |
26260 KB |
Output is correct |
77 |
Correct |
478 ms |
22548 KB |
Output is correct |