CSU-2173 Use FFT

Description

Bobo computes the product P(x)⋅Q(x)=\(c_0 + c_1x + … + c_{n+m}x^{n + m}\) for two polynomials P(x)=\(a_0 + a_1x + … + a_nx^n\) and Q(x)=\(b_0 + b_1x + … + b_mx^m\). Find $ (c_L + c_{L + 1} + … + c_R) $ modulo ($10^9 $ + 7) for given L and R.

  • 1 ≤ n, m ≤ 5 × \(10^5\)
  • 0 ≤ L ≤ R ≤ n + m
  • 0 ≤ \(a_i, b_i\) ≤ \(10^9\)
  • Both the sum of n and the sum of m do not exceed \(10^6\).

Input

The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains four integers n, m, L, R.

The second line contains (n + 1) integers \(a_0, a_1, …, a_n\).

The third line contains (m + 1) integers \(b_0, b_1, …, b_m\).

Output

For each test case, print an integer which denotes the reuslt.

Sample Input

1 1 0 2
1 2
3 4
1 1 1 2
1 2
3 4
2 3 0 5
1 2 999999999
1 2 3 1000000000

Sample Output

21
18
5

题解

这题标题是Use FFT所以当然是用FFT做了(滑稽)

这题其实是个数学题+找规律题,借用一张图片



所以我们对b求前缀和,用a去乘,注意细节就好了

#include<bits/stdc++.h>
#define maxn 500050
#define p 1000000007
using namespace std;
typedef long long ll;
ll a[maxn], b[maxn];
ll pre[maxn * 2];
int main() {
int n, m, l, r;
while (scanf("%d%d%d%d", &n, &m, &l, &r) != EOF) {
for (int i = 1; i <= n + 1; i++) {
scanf("%lld", &a[i]);
}
for (int i = 1; i <= m + 1; i++) {
scanf("%lld", &b[i]);
pre[i] = (pre[i - 1] + b[i]) % p;
}
for (int i = m + 2; i <= r + 1; i++) {
pre[i] = pre[i - 1];
}
ll ans = 0;
for (int i = 1; i <= n + 1; i++) {
ans = (ans + a[i] * (pre[r + 1] - pre[l] + p) % p) % p;
if (l > 0) l--;
if (r >= 0) r--;
}
printf("%lld\n", (ans + p) % p);
}
return 0;
}

最新文章

  1. AMD and CMD are dead之KMD.js版本0.0.2发布
  2. netstat监控大量ESTABLISHED连接与Time_Wait连接问题
  3. 谢欣伦 - OpenDev原创教程 - 设备查找类CxDeviceFind &amp; CxDeviceMapFind
  4. android EditText光标位置(定位到最后)
  5. clearfix清除浮动进化史
  6. 【原】Oracle11gR2图文安装
  7. 11种dialogBox样式打包开源,逐一详解
  8. ES mlockall作用——preventing that memory from being paged to the swap area
  9. IOS 日期选择
  10. ASP.NET MVC 文件上传和路径处理
  11. 蓝桥网试题 java 基础练习 查找整数
  12. java 基础知识五 数组
  13. python自带库及第三方库api察看
  14. Shell 脚本实践
  15. css自定义checkbox和radio样式
  16. IO流_文件切割与合并
  17. top结果解释
  18. DockerFile(保你会版本)(七)
  19. 封装JSON数据转自定义HTML方法parseHTML
  20. SpringMVC系列(十三)异常处理

热门文章

  1. Hadoop 分片、分组与排序
  2. SQL中如何避免书签查找
  3. python+selenium之自动生成excle,保存到指定的目录下
  4. hive 报错FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient FAILED: Execu
  5. Head First HTML与CSS阅读笔记(二)
  6. IOS 绘制基本图形( 画圆、画线、画圆弧、绘制三角形、绘制四边形)
  7. hdu-3371 Connect the Cities---kruskal
  8. 题解 CF20A 【BerOS file system】
  9. Vue之Vue-touch的使用
  10. mysql基础,数据表的类型