Multiplication

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

If C=AB, then

C[k]=max(i,j)=kA[i]B[j]mod(109+7)

.

 

Work out sequence C=ABfor 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 nn integers a1,a2,,ana1,a2,…,an , which denote sequence A.

The thrid line contains nn integers b1,b2,,bnb1,b2,…,bn , which denote sequenceB.

(1n105,0ai,bi109)

Output

nn integers, which denotes sequence C.

Sample Input

2
1 2
3 4

Sample Output

3 18 

Source

ftiasch

Manager

 
题意:  长度为n的a,b序列   求C[k]=max(i,j)A[i]B[j]mod(109+7)
 
题解:  max(i,j) 可以看出 相乘的两个数中一定有a[n]或者b[n]
          前缀和处理
 
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<stack>
 6 #define ll long long 
 7 #define pi acos(-1.0)
 8 #define mod 1000000007
 9 using namespace std;
10 int n;    
11 ll a[100005];
12 ll b[100005];
13 ll suma[100005];
14 ll sumb[100005];
15 ll ans;
16 ll gg[100005];
17 int main()
18 {
19     while(scanf("%d",&n)!=EOF)
20     {
21         suma[0]=0;
22         sumb[0]=0;
23         a[0]=0;
24         b[0]=0;
25         for(int i=1;i<=n;i++)
26         {
27             scanf("%d",&a[i]);
28             suma[i]=(suma[i-1]+a[i])%mod;
29         }
30             for(int i=1;i<=n;i++)
31         {
32             scanf("%d",&b[i]);
33             sumb[i]=(sumb[i-1]+b[i])%mod;
34         }
35         ans=0;
36         for(int i=1;i<=n;i++)
37         {
38           ans=((a[i]*b[i]%mod+a[i]*sumb[i-1]%mod+b[i]*suma[i-1]%mod))%mod;
39           gg[i]=ans;
40         }
41         printf("%lld",gg[1]);
42         for(int i=2;i<=n;i++)
43          printf(" %lld",gg[i]);
44          cout<<endl; 
45     }
46     return 0;
47 }