이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=5e5+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... |