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 <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=1e4+5,M=1e9+7;
int a[N],n,b[N],p2[N],c[2*N],p[N],s[N];
int pow(int x,int y){
if (!y) return 1;
int z=pow(x,y/2);
z=z*z%M;
if (y&1) z=z*x%M;
return z;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
p2[0]=1;
for (int i=1;i<N;i++) p2[i]=p2[i-1]*2%M;
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i],c[i]=a[i];
for (int i=1;i<=n;i++) cin>>b[i],c[i+n]=b[i];
sort(c+1,c+1+2*n);
int ans=0;
s[n+1]=1;p[0]=1;
for (int j=1;j<=2*n;j++){
if (c[j]==c[j-1]) continue;
for (int i=n;i;i--) s[i]=s[i+1]*((a[i]<c[j])+(b[i]<c[j]))%M;
for (int i=1;i<=n;i++) p[i]=p[i-1]*((a[i]<c[j])+(b[i]<c[j]))%M;
for (int i=1;i<=n;i++){
int l=(p2[i-1]-p[i-1]+M)%M,r=(p2[n-i]-s[i+1]+M)%M;
l=l*r%M;
if (a[i]<c[j]) ans=(ans+l*(c[j]-c[j-1])%M)%M;
if (b[i]<c[j]) ans=(ans+l*(c[j]-c[j-1])%M)%M;
}
}
cout<<ans<<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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |