标签:
If C=A?B, then
.
Work out sequence C=A?Bfor given sequence A and B.
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.
(1≤n≤105,0≤ai,bi≤109)
nn integers, which denotes sequence C.
2 1 2 3 4
3 18
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 }
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5538624.html