#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define int long long
int mod=1e9+7;
int l=20;
int32_t main()
{
int n;
cin>>n;
vector<int> h(n),w(n);
for(int i=0;i<n;i++)
cin>>h[i];
for(int i=0;i<n;i++)
cin>>w[i];
int ans=0;
for(int i=0;i<n;i++)
{
int row,col;
row=(((h[i]+1)*h[i])/2)%mod;
col=(((w[i]+1)*w[i])/2)%mod;
ans=(ans+row*col)%mod;
}
vector<array<int,20>> sparce(n);
for(int i=0;i<n;i++)
{
sparce[i][0]=h[i];
}
for(int b=1;b<20;b++)
{
for(int i=0;i<n;i++)
{
if(i+(1<<(b-1))<n)
sparce[i][b]=min(sparce[i][b-1],sparce[i+(1<<(b-1))][b-1]);
}
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int d=j+1-i;
int k=__lg(d);
int mn=min(sparce[i][k],sparce[j+1-(1<<k)][k]);
ans=(ans+((w[i]*w[j])%mod)*(((mn*(mn+1))/2)%mod))%mod;
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |