#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e16;
const ll mod2 = 1e9 + 7;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
ll n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r,p ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
vector<int> a;
vector<int> d;
vector<int> b;
vector<int> c;
vector<int> sor;
int ac_lef[100001];
int ac_right[100001];
int nearest[200001];
int pre[200001];
int hihi[200001];
int suf[200001];
void inside(vector<int> a,vector<int> b,int x,int y)
{
for(int i=0; i<n; i++)
{
ac_lef[i]=n-(upper_bound(b.begin(),b.end(),a[i]+x)-b.begin());/// can co it nhat bao nhieu con lon hon
ac_right[i]=n-(lower_bound(b.begin(),b.end(),a[i]-x)-b.begin())-1;
/// ac_left<=x<=ac_right
}
for(int i=0; i<n; i++)
{
if(y==0)
{
if(nearest[i]-i<ac_lef[i])suf[i]++;
if(n-i-1<ac_lef[i])///it nhat can ac_left canh lon hon => ac_left+i-1 ko dc do xuong
{
suf[min(ac_lef[i]+i-1,i+n-1)-n+1]++;
}
if(nearest[i]>i+ac_right[i])
{
pre[max(i+ac_right [i]+1,n-1)-n+1]++;
pre[i+1]--;
}
}
else if(i!=n-1)
{
if(i+n-nearest[i+n]<ac_lef[i])pre[i+1]++;
if(i<ac_lef[i])
{
pre[max(i+n-ac_lef[i]+1,i+1)]++;
}
if(nearest[i+n]<i+n-ac_right[i])
{
suf[min(i+n-ac_right[i]-1,n-1)]++;
suf[i]--;
}
}
}
}
void outside(vector<int> a,vector<int> b,int x,int y)
{
for(int i=0; i<n; i++)
{
ac_lef[i]=n-(upper_bound(b.begin(),b.end(),a[i]+x)-b.begin());/// can co it nhat bao nhieu con lon hon
ac_right[i]=n-(lower_bound(b.begin(),b.end(),a[i]-x)-b.begin())-1;
/// ac_left<=x<=ac_right
}
for(int i=0; i<n; i++)
{
if(y==0)
{
if(i==n-1) continue;
int least=hihi[i]-(i+n);
if(least<ac_lef[i])
{
pre[i+1]++;
pre[i+ac_lef[i]+1]--;
}
if(least>ac_right[i])
pre[i+1]++;
else
pre[i+ac_right[i]+2]++;
}
else
{
if(i==0) continue;
int least=(i)-hihi[i+n];
if(least<ac_lef[i])
{
suf[i]++;
if(i-ac_lef[i]>=0)
suf[i-ac_lef[i]]--;
}
if(least>ac_right[i])
suf[i]++;
else if(i-ac_right[i]-1>=0)
suf[i-ac_right[i]-1]++;
}
}
}
bool get()
{
for(int i=1; i<=n; i++)
pre[i]+=pre[i-1];
for(int i=n-1; i>=0; --i)
suf[i]+=suf[i+1];
for(int i=1; i<n; i++)
if(!pre[i]&&!suf[i])
{
return 1;
}
return 0;
}
bool solve(vector<int> b,vector<int> c,int x)
{
memset(pre,0,sizeof pre);
memset(suf,0,sizeof suf);
/// find l and r of i
inside(a,b,x,0);
outside(a,c,x,0);
inside(d,b,x,n);
outside(d,c,x,n);
if(get())return 1;
for(int i=0; i<n; i++)
{
if(abs(a[i]-b[i])>x) return 0;
}
for(int i=n-1; i>=0; --i)
{
if(abs(d[i]-c[n-1-i])>x) return 0;
}
return 1;
/// for(int i=1; i<=n; i++)
}
bool check(int x)
{
return (solve(b,c,x)|solve(c,b,x));
}
void phongbeo()
{
cin>>n;
a.resize(n);
d.resize(n);
b.resize(n);
c.resize(n);
for(int i=0; i<n; i++)
cin>>a[i];
for(int i=0; i<n; i++)
cin>>d[i];
l=0;
for(int i=n-1; i>=0; i--)
{
while(l<n&&d[l]>=a[i])l++;
hihi[i]=l+n-1;
//cout<<hihi[i]<<" "<<i,down
nearest[i]=min(l+n-1,i+n-1);
/// cout<<l<<" "<<i<<" "<<nearest[i]<<" "<<i+n-1,down
}
l=n-1;
for(int i=0; i<n; i++)
{
while(l>=0&&a[l]>d[i]) l--;
hihi[i+n]=l+1;
nearest[i+n]=max(l+1,i+1);
}
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());
l=0;
r=1e9;
while(l<=r)
{
int mid=l+r>>1;
if(check(mid))r=mid-1;
else l=mid+1;
}
cout<<r+1;
}
Compilation message
Main.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
75 | main()
| ^~~~
Main.cpp: In function 'void phongbeo()':
Main.cpp:253:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
253 | int mid=l+r>>1;
| ~^~
Main.cpp: In function 'int main()':
Main.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:79:9: note: in expansion of macro 'fin'
79 | fin(task);
| ^~~
Main.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:80:9: note: in expansion of macro 'fou'
80 | fou(task);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6736 KB |
Output is correct |
2 |
Correct |
6 ms |
6736 KB |
Output is correct |
3 |
Correct |
6 ms |
6792 KB |
Output is correct |
4 |
Correct |
5 ms |
6736 KB |
Output is correct |
5 |
Correct |
6 ms |
6736 KB |
Output is correct |
6 |
Correct |
6 ms |
6736 KB |
Output is correct |
7 |
Correct |
6 ms |
6784 KB |
Output is correct |
8 |
Correct |
7 ms |
6736 KB |
Output is correct |
9 |
Correct |
5 ms |
6788 KB |
Output is correct |
10 |
Correct |
6 ms |
6736 KB |
Output is correct |
11 |
Correct |
6 ms |
6900 KB |
Output is correct |
12 |
Correct |
6 ms |
6736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6736 KB |
Output is correct |
2 |
Correct |
6 ms |
6736 KB |
Output is correct |
3 |
Correct |
6 ms |
6792 KB |
Output is correct |
4 |
Correct |
5 ms |
6736 KB |
Output is correct |
5 |
Correct |
6 ms |
6736 KB |
Output is correct |
6 |
Correct |
6 ms |
6736 KB |
Output is correct |
7 |
Correct |
6 ms |
6784 KB |
Output is correct |
8 |
Correct |
7 ms |
6736 KB |
Output is correct |
9 |
Correct |
5 ms |
6788 KB |
Output is correct |
10 |
Correct |
6 ms |
6736 KB |
Output is correct |
11 |
Correct |
6 ms |
6900 KB |
Output is correct |
12 |
Correct |
6 ms |
6736 KB |
Output is correct |
13 |
Correct |
6 ms |
6904 KB |
Output is correct |
14 |
Correct |
5 ms |
6736 KB |
Output is correct |
15 |
Correct |
6 ms |
6736 KB |
Output is correct |
16 |
Correct |
6 ms |
6736 KB |
Output is correct |
17 |
Correct |
5 ms |
6736 KB |
Output is correct |
18 |
Correct |
6 ms |
6784 KB |
Output is correct |
19 |
Correct |
7 ms |
6736 KB |
Output is correct |
20 |
Correct |
6 ms |
6736 KB |
Output is correct |
21 |
Correct |
6 ms |
6736 KB |
Output is correct |
22 |
Correct |
6 ms |
6736 KB |
Output is correct |
23 |
Correct |
5 ms |
6612 KB |
Output is correct |
24 |
Correct |
5 ms |
6736 KB |
Output is correct |
25 |
Correct |
6 ms |
6784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6736 KB |
Output is correct |
2 |
Correct |
6 ms |
6736 KB |
Output is correct |
3 |
Correct |
6 ms |
6792 KB |
Output is correct |
4 |
Correct |
5 ms |
6736 KB |
Output is correct |
5 |
Correct |
6 ms |
6736 KB |
Output is correct |
6 |
Correct |
6 ms |
6736 KB |
Output is correct |
7 |
Correct |
6 ms |
6784 KB |
Output is correct |
8 |
Correct |
7 ms |
6736 KB |
Output is correct |
9 |
Correct |
5 ms |
6788 KB |
Output is correct |
10 |
Correct |
6 ms |
6736 KB |
Output is correct |
11 |
Correct |
6 ms |
6900 KB |
Output is correct |
12 |
Correct |
6 ms |
6736 KB |
Output is correct |
13 |
Correct |
6 ms |
6904 KB |
Output is correct |
14 |
Correct |
5 ms |
6736 KB |
Output is correct |
15 |
Correct |
6 ms |
6736 KB |
Output is correct |
16 |
Correct |
6 ms |
6736 KB |
Output is correct |
17 |
Correct |
5 ms |
6736 KB |
Output is correct |
18 |
Correct |
6 ms |
6784 KB |
Output is correct |
19 |
Correct |
7 ms |
6736 KB |
Output is correct |
20 |
Correct |
6 ms |
6736 KB |
Output is correct |
21 |
Correct |
6 ms |
6736 KB |
Output is correct |
22 |
Correct |
6 ms |
6736 KB |
Output is correct |
23 |
Correct |
5 ms |
6612 KB |
Output is correct |
24 |
Correct |
5 ms |
6736 KB |
Output is correct |
25 |
Correct |
6 ms |
6784 KB |
Output is correct |
26 |
Correct |
18 ms |
6992 KB |
Output is correct |
27 |
Correct |
22 ms |
7028 KB |
Output is correct |
28 |
Correct |
21 ms |
6876 KB |
Output is correct |
29 |
Correct |
8 ms |
6736 KB |
Output is correct |
30 |
Correct |
32 ms |
6992 KB |
Output is correct |
31 |
Correct |
25 ms |
6992 KB |
Output is correct |
32 |
Correct |
14 ms |
7048 KB |
Output is correct |
33 |
Correct |
10 ms |
6736 KB |
Output is correct |
34 |
Correct |
17 ms |
6992 KB |
Output is correct |
35 |
Correct |
16 ms |
6880 KB |
Output is correct |
36 |
Correct |
35 ms |
7012 KB |
Output is correct |
37 |
Correct |
19 ms |
6992 KB |
Output is correct |
38 |
Correct |
18 ms |
6992 KB |
Output is correct |
39 |
Correct |
19 ms |
6992 KB |
Output is correct |
40 |
Correct |
23 ms |
7160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
68 ms |
34952 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6736 KB |
Output is correct |
2 |
Correct |
6 ms |
6736 KB |
Output is correct |
3 |
Correct |
6 ms |
6792 KB |
Output is correct |
4 |
Correct |
5 ms |
6736 KB |
Output is correct |
5 |
Correct |
6 ms |
6736 KB |
Output is correct |
6 |
Correct |
6 ms |
6736 KB |
Output is correct |
7 |
Correct |
6 ms |
6784 KB |
Output is correct |
8 |
Correct |
7 ms |
6736 KB |
Output is correct |
9 |
Correct |
5 ms |
6788 KB |
Output is correct |
10 |
Correct |
6 ms |
6736 KB |
Output is correct |
11 |
Correct |
6 ms |
6900 KB |
Output is correct |
12 |
Correct |
6 ms |
6736 KB |
Output is correct |
13 |
Correct |
6 ms |
6904 KB |
Output is correct |
14 |
Correct |
5 ms |
6736 KB |
Output is correct |
15 |
Correct |
6 ms |
6736 KB |
Output is correct |
16 |
Correct |
6 ms |
6736 KB |
Output is correct |
17 |
Correct |
5 ms |
6736 KB |
Output is correct |
18 |
Correct |
6 ms |
6784 KB |
Output is correct |
19 |
Correct |
7 ms |
6736 KB |
Output is correct |
20 |
Correct |
6 ms |
6736 KB |
Output is correct |
21 |
Correct |
6 ms |
6736 KB |
Output is correct |
22 |
Correct |
6 ms |
6736 KB |
Output is correct |
23 |
Correct |
5 ms |
6612 KB |
Output is correct |
24 |
Correct |
5 ms |
6736 KB |
Output is correct |
25 |
Correct |
6 ms |
6784 KB |
Output is correct |
26 |
Correct |
18 ms |
6992 KB |
Output is correct |
27 |
Correct |
22 ms |
7028 KB |
Output is correct |
28 |
Correct |
21 ms |
6876 KB |
Output is correct |
29 |
Correct |
8 ms |
6736 KB |
Output is correct |
30 |
Correct |
32 ms |
6992 KB |
Output is correct |
31 |
Correct |
25 ms |
6992 KB |
Output is correct |
32 |
Correct |
14 ms |
7048 KB |
Output is correct |
33 |
Correct |
10 ms |
6736 KB |
Output is correct |
34 |
Correct |
17 ms |
6992 KB |
Output is correct |
35 |
Correct |
16 ms |
6880 KB |
Output is correct |
36 |
Correct |
35 ms |
7012 KB |
Output is correct |
37 |
Correct |
19 ms |
6992 KB |
Output is correct |
38 |
Correct |
18 ms |
6992 KB |
Output is correct |
39 |
Correct |
19 ms |
6992 KB |
Output is correct |
40 |
Correct |
23 ms |
7160 KB |
Output is correct |
41 |
Runtime error |
68 ms |
34952 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |