CSU-2173 Use FFT
2024-10-21 10:08:49
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;
}
最新文章
- AMD and CMD are dead之KMD.js版本0.0.2发布
- netstat监控大量ESTABLISHED连接与Time_Wait连接问题
- 谢欣伦 - OpenDev原创教程 - 设备查找类CxDeviceFind &; CxDeviceMapFind
- android EditText光标位置(定位到最后)
- clearfix清除浮动进化史
- 【原】Oracle11gR2图文安装
- 11种dialogBox样式打包开源,逐一详解
- ES mlockall作用——preventing that memory from being paged to the swap area
- IOS 日期选择
- ASP.NET MVC 文件上传和路径处理
- 蓝桥网试题 java 基础练习 查找整数
- java 基础知识五 数组
- python自带库及第三方库api察看
- Shell 脚本实践
- css自定义checkbox和radio样式
- IO流_文件切割与合并
- top结果解释
- DockerFile(保你会版本)(七)
- 封装JSON数据转自定义HTML方法parseHTML
- SpringMVC系列(十三)异常处理
热门文章
- Hadoop 分片、分组与排序
- SQL中如何避免书签查找
- python+selenium之自动生成excle,保存到指定的目录下
- hive 报错FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient FAILED: Execu
- Head First HTML与CSS阅读笔记(二)
- IOS 绘制基本图形( 画圆、画线、画圆弧、绘制三角形、绘制四边形)
- hdu-3371 Connect the Cities---kruskal
- 题解 CF20A 【BerOS file system】
- Vue之Vue-touch的使用
- mysql基础,数据表的类型