CSU-2173 Use FFT
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;
}
CSU-2173 Use FFT的更多相关文章
- 并行计算提升32K*32K点(32位浮点数) FFT计算速度(4核八线程E3处理器)
对32K*32K的随机数矩阵进行FFT变换,数的格式是32位浮点数.将产生的数据存放在堆上,对每一行数据进行N=32K的FFT,记录32K次fft的时间. 比较串行for循环和并行for循环的运行时间 ...
- 【BZOJ-2179&2194】FFT快速傅里叶&快速傅里叶之二 FFT
2179: FFT快速傅立叶 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2978 Solved: 1523[Submit][Status][Di ...
- 为什么FFT时域补0后,经FFT变换就是频域进行内插?
应该这样来理解这个问题: 补0后的DFT(FFT是DFT的快速算法),实际上公式并没变,变化的只是频域项(如:补0前FFT计算得到的是m*2*pi/M处的频域值, 而补0后得到的是n*2*pi/N处的 ...
- FFT NNT
算算劳资已经多久没学新算法了,又要重新开始学辣.直接扔板子,跑...话说FFT算法导论里讲的真不错,去看下就懂了. //FFT#include <cstdio> #include < ...
- CC countari & 分块+FFT
题意: 求一个序列中顺序的长度为3的等差数列. SOL: 对于这种计数问题都是用个数的卷积来进行统计.然而对于这个题有顺序的限制,不好直接统计,于是竟然可以分块?惊为天人... 考虑分块以后的序列: ...
- ECF R9(632E) & FFT
Description: 上一篇blog. Solution: 同样我们可以用fft来做...就像上次写的那道3-idoit一样,对a做k次卷积就好了. 同样有许多需要注意的地方:我们只是判断可行性, ...
- fft练习
数学相关一直都好弱啊>_< 窝这个月要补一补数学啦, 先从基础的fft补起吧! 现在做了 道. 窝的fft 模板 (bzoj 2179) #include <iostream> ...
- FFT时域与频域的关系,以及采样速率与采样点的影响
首先对于FFT来说,输入的信号是一个按一定采样频率获得的信号序列,而输出是每个采样点对应的频率的幅度(能量). 下面详细分析: 在FFT的输出数据中,第一个值是直流分量的振幅(这样对应周期有无穷的可能 ...
- 【玩转单片机系列002】 如何使用STM32提供的DSP库进行FFT
前些日子,因为需要在STM32F103系列处理器上,对采集的音频信号进行FFT,所以花了一些时间来研究如何高效并精确的在STM32F103系列处理器上实现FFT.在网上找了很多这方面的资料做实验并进行 ...
- FFT
void FFT(complex a[],int n,int fl){ ,j=n/;i<n;i++){ if (i<j) {complex t=a[i];a[i]=a[j];a[j]=t; ...
随机推荐
- #linux 下Sublime的安装
1.Download http://www.sublimetext.com/2 Installtion use tar 解压压缩包,这里我将包改了个名字,这样就不用写空格的转义字符了,改成Subli ...
- IOS 九宫图解锁(封装)
NJLockView.h /.m @class NJLockView; @protocol NJLockViewDelegate <NSObject> - (void)lockViewDi ...
- openlayers 初步认识(转)
OpenLayers是一个开源的js框架,用于在您的浏览器中实现地图浏览的效果和基本的zoom,pan等功能.OpenLayers支持的地图来源 包括了WMS,GoogleMap,KaMap,MSVi ...
- vuejs计算属性和侦听器
<div id='root'> 姓:<input v-model='firstName'/> 名:<input v-model='secondName'/> < ...
- jQuery Pagination分页插件--刷新
源码地址:https://github.com/SeaLee02/FunctionModule/blob/master/UploadFiles/WebDemo/FenYE/FenYeDemo.aspx ...
- CSVDE
csvde -f C:\export_OrganizationalUnit.csv -r '(objectClass=organizationalUnit)' -l 'displayName,prox ...
- AJAX进行分页
新建数据集:PagingDataSet.xsd SELECT * from ( select id, areaID, area, father,Row_Number() over (order by ...
- 前端小记3——iOS与Android问题
1.消除transition闪屏 (1)-webkit-transform-style:preserve-3d; /*设置内嵌的元素在 3D 空间如何呈现:保留 3D*/ (2)-webkit-ba ...
- linux apache 不解析php文件显示源码
首先检查是否安装PHP 没有的话就先安装 如果安装过 在/etc/httpd/conf/httpd.conf文件中 在<IfModule mime_module>里面 AddType ap ...
- notify()和notifyAll()主要区别
notify()和notifyAll()都是Object对象用于通知处在等待该对象的线程的方法. void notify(): 唤醒一个正在等待该对象的线程.void notifyAll(): 唤醒所 ...