Multiplication
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 128000/64000 KB (Java/Others)
Problem Description
If C=A⋄B , then
C[k]=∑max(i,j)=kA[i]⋅B[j]mod(109+7)
.
Work out sequence C=A⋄B for given sequence A and B .
Input
The first line contains a integer n , which denotes the length of sequence A,B .
The second line contains n integers a1,a2,…,an , which denote sequence A .
The thrid line contains n integers b1,b2,…,bn , which denote sequence B .
( 1≤n≤105,0≤ai,bi≤109 )
Output
n integers, which denotes sequence C .
Sample Input
2 1 2 3 4
Sample Output
3 18
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
const ll mod=1000000007;
const int N=100005;
int n;
ll a[N],b[N];
ll suma[N],sumb[N];
inline void In(){
suma[0]=sumb[0]=0;
rep(i,1,n+1){
scanf("%lld",&a[i]);
suma[i]=(suma[i-1]+a[i])%mod;
}
rep(i,1,n+1){
scanf("%lld",&b[i]);
sumb[i]=(sumb[i-1]+b[i])%mod;
}
}
inline ll Ans(int k){
ll ans1=a[k]*sumb[k]%mod;
ll ans2=b[k]*suma[k]%mod;
ll ans3=a[k]*b[k]%mod;
return (ans1+ans2-ans3+mod)%mod;
}
inline void Work(){
rep(i,1,n+1){
printf("%lld",Ans(i));
if(i==n) puts("");
else putchar(' ');
}
}
int main(){
while(~scanf("%d",&n)){
In();
Work();
}
return 0;
}