Multiplication

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (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⋄Bfor 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.

(1≤n≤105,0≤ai,bi≤109)

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]
          前缀和处理
 
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#define ll long long
#define pi acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
ll a[];
ll b[];
ll suma[];
ll sumb[];
ll ans;
ll gg[];
int main()
{
while(scanf("%d",&n)!=EOF)
{
suma[]=;
sumb[]=;
a[]=;
b[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
suma[i]=(suma[i-]+a[i])%mod;
}
for(int i=;i<=n;i++)
{
scanf("%d",&b[i]);
sumb[i]=(sumb[i-]+b[i])%mod;
}
ans=;
for(int i=;i<=n;i++)
{
ans=((a[i]*b[i]%mod+a[i]*sumb[i-]%mod+b[i]*suma[i-]%mod))%mod;
gg[i]=ans;
}
printf("%lld",gg[]);
for(int i=;i<=n;i++)
printf(" %lld",gg[i]);
cout<<endl;
}
return ;
}
 
 

ACdream 1029 前缀和的更多相关文章

  1. Leetcode 1029. 可被 5 整除的二进制前缀

    1029. 可被 5 整除的二进制前缀  显示英文描述 我的提交返回竞赛   用户通过次数467 用户尝试次数662 通过次数477 提交次数1964 题目难度Easy 给定由若干 0 和 1 组成的 ...

  2. HDU 5452——Minimum Cut——————【树链剖分+差分前缀和】ACdream 1429——Diversion——————【树链剖分】

    Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Tota ...

  3. [ACDream 1430]SETI 后缀数组

    题目链接:http://acdream.info/problem?pid=1430 题目大意:给你一个长度不超过10000的字符串,问你出现过两次或两次以上的不重叠的子串有多少个. 后缀数组计算出he ...

  4. [ACdream] 女神教你字符串——三个气球

    Problem Description 女神邀请众ACdream开联欢会,显然作为ACM的佼佼者,气球是不能少的~.女神准备了三种颜色的气球,红色,黄色,绿色(交通信号灯?) 有气球还不能满足女神,女 ...

  5. ACdreamoj 1011(树状数组维护字符串hash前缀和)

    题目链接:http://acdream.info/problem? pid=1019 题意:两种操作,第一种将字符串某个位置的字符换为还有一个字符.另外一种查询某个连续子序列是否是回文串: 解法:有两 ...

  6. ACdream1726-A Math game+(DFS+二分)+(DFS+前缀和)

    传送门 官方题解:http://acdream.info/topic?tid=4246 参考:https://www.cnblogs.com/nowandforever/p/4492428.html ...

  7. HDU1671——前缀树的一点感触

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...

  8. 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed

    之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...

  9. ASP.NET Core MVC 配置全局路由前缀

    前言 大家好,今天给大家介绍一个 ASP.NET Core MVC 的一个新特性,给全局路由添加统一前缀.严格说其实不算是新特性,不过是Core MVC特有的. 应用背景 不知道大家在做 Web Ap ...

随机推荐

  1. Docker自学纪实(二)Docker基本操作

    安装docker 以CentOS7为例: 安装:yum -y install docker 启动:systemctl start docker 设置开机自启:systemctl enable dock ...

  2. form表单submit按钮提交页面不跳转

    方案一 <html> <body> <form action="" method="post" target="nm_i ...

  3. C语言进阶——const 和 volatile 分析09

    const只读变量: const修饰的变量是只读的,本质还是一个变量 const修饰的局部变量在栈上分配空间 const修饰的全局变量在全局函数区分配资源空间 const只在编译器有用,在运行期无用 ...

  4. POJ:1703-Find them, Catch them(并查集好题)(种类并查集)

    Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 49867 Accepted: 153 ...

  5. The Road to learn React书籍学习笔记(第一章)

    react灵活的生态圈 Small Application Boilerplate: create-react-app Utility: JavaScript ES6 and beyond Styli ...

  6. 19,Ubuntu安装之python开发

      什么??公司要用Ubuntu(乌班图)?不会用??怎么进行python开发??? 乌班图操作系统下载地址:http://releases.ubuntu.com/18.04/ubuntu-18.04 ...

  7. 洛谷P1451 求细胞数量

    求细胞数量 题目链接 这道题大概是一个最简单的联通块的题了qwq 注意枚举起点的时候 一定不要从0开始不然你就会从0进入到了其他联通块中从而多查. 一定看清题意这道题不是同色为联通块!!! AC代码如 ...

  8. Spark 的情感分析

    Spark 的情感分析 本文描述了基于 Spark 如何构建一个文本情感分析系统.文章首先介绍文本情感分析基本概念和应用场景,其次描述采用 Spark 作为分析的基础技术平台的原因和本文使用到技术组件 ...

  9. 斐波那契数列(Fibonacci) iOS

    斐波那契数列Fibonacci 斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2 ...

  10. 发布“豪情”设计的新博客皮肤-darkgreentrip

    豪情 (http://www.cnblogs.com/jikey/)是一名在上海的前端开发人员,长期驻扎在园子里.他为大家设计了一款新的博客皮肤——darkgreentrip. 以下是该博客皮肤的介绍 ...