【传送门】

FFT第一题!

构造多项式 $A(x) = \sum x ^ {s_i}$。

不考虑题目中 $i < j < k$ 的条件,那么 $A^3(x)$ 每一项对应的系数就是答案了。

考虑容斥。

$$(\sum x)^3 = \sum x^3 + 3 \sum x^2 y + 6\sum xyz$$

$$(\sum x^2) (\sum x)= \sum x^3 + \sum x^2 y$$

所以 $$\sum xyz = \dfrac{(\sum x)^3 - 3 (\sum x^2)(\sum x) + 2 \sum x^3}{6}$$

#include <bits/stdc++.h>

struct Complex {
double r, i;
Complex(double r = 0.0, double i = 0.0): r(r), i(i) {}
Complex operator + (const Complex &p) const { return Complex(r + p.r, i + p.i); }
Complex operator - (const Complex &p) const { return Complex(r - p.r, i - p.i); }
Complex operator * (const Complex &p) const { return Complex(r * p.r - i * p.i, r * p.i + i * p.r); }
}; const double pi = acos(-1.0);
const int N = 2e5 + ;
int n, limit, r[N], l;
int v[N], A[N], B[N], C[N];
Complex a[N], b[N], c[N]; void FFT(Complex *a, int pd) {
for (int i = ; i < limit; i++)
if (i < r[i])
std::swap(a[i], a[r[i]]);
for (int mid = ; mid < limit; mid <<= ) {
Complex wn = Complex(cos(pi / mid), pd * sin(pi / mid));
for (int l = mid << , j = ; j < limit; j += l) {
Complex w = Complex(1.0, 0.0);
for (int k = ; k < mid; k++, w = w * wn) {
Complex u = a[k + j], v = w * a[k + j + mid];
a[k + j] = u + v;
a[k + j + mid] = u - v;
}
}
}
if (pd == -)
for (int i = ; i < limit; i++)
a[i] = Complex(a[i].r / limit, a[i].i / limit);
} int main() {
scanf("%d", &n);
for (int i = ; i < n; i++) {
int x;
scanf("%d", &x);
x += ;
A[x]++;
B[x * ]++;
C[x * ]++;
}
for (int i = ; i <= ; i++)
a[i] = Complex((double)A[i], 0.0);
for (int i = ; i <= ; i++)
b[i] = Complex((double)B[i], 0.0);
limit = ;
while (limit <= + )
limit <<= , l++;
for (int i = ; i < limit; i++)
r[i] = r[i >> ] >> | ((i & ) << (l - ));
FFT(a, );
FFT(b, );
for (int i = ; i < limit; i++)
b[i] = b[i] * a[i];
for (int i = ; i < limit; i++)
a[i] = a[i] * a[i] * a[i];
FFT(a, -);
FFT(b, -);
for (int i = ; i <= ; i++) {
long long ans = (long long)((a[i].r - 3.0 * b[i].r + 2.0 * C[i]) / 6.0 + 0.5);
if (ans > )
printf("%d : %lld\n", i - , ans);
}
return ;
}

SPOJ - Triple Sums的更多相关文章

  1. 2018.11.18 spoj Triple Sums(容斥原理+fft)

    传送门 这次fftfftfft乱搞居然没有被卡常? 题目简述:给你nnn个数,每三个数ai,aj,ak(i<j<k)a_i,a_j,a_k(i<j<k)ai​,aj​,ak​( ...

  2. SPOJ Triple Sums(FFT+容斥原理)

    # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream& ...

  3. SPOJ TSUM Triple Sums(FFT + 容斥)

    题目 Source http://www.spoj.com/problems/TSUM/ Description You're given a sequence s of N distinct int ...

  4. SPOJ:Triple Sums(母函数+FFT)

    You're given a sequence s of N distinct integers.Consider all the possible sums of three integers fr ...

  5. spoj TSUM - Triple Sums fft+容斥

    题目链接 首先忽略 i < j < k这个条件.那么我们构造多项式$$A(x) = \sum_{1现在我们考虑容斥:1. $ (\sum_{}x)^3 = \sum_{}x^3 + 3\s ...

  6. Spoj 8372 Triple Sums

    题意:给你n个数字,对于任意s,s满足\(s=u_i+u_j+u_k,i<j<k\),要求出所有的s和对应满足条件的i,j,k的方案数 Solution: 构造一个函数:\(A(x)=\s ...

  7. SPOJ #453. Sums in a Triangle (tutorial)

    It is a small fun problem to solve. Since only a max sum is required (no need to print path), we can ...

  8. [SP8372-TSUM]Triple Sums

    题面在这里 description 某\(B\)姓\(OJ\)权限题 给出\(n\)个正整数\(a[i]\),求\(i<j<k\)且\(S=a[i]+a[j]+a[k]\)的三元组\((i ...

  9. spoj-TSUM Triple Sums

    题目描述 题解: 很吊的容斥+$FFT$,但是并不难. 首先,由于有重复,我们要容斥. 怎么办? 记录三个多项式, 只取一个:$w1$; 相同物体拿两个:$w2$; 相同物体拿三个:$w3$; 然后答 ...

随机推荐

  1. Paper | FFDNet: Toward a Fast and Flexible Solution for CNN based Image Denoising

    目录 故事背景 核心思想 FFDNet 网络设置 噪声水平图 对子图像的去噪 保证噪声水平图的有效性 如何盲处理 为啥不用短连接 裁剪像素范围 实验 关于噪声水平图的敏感性 盲处理 发表在2018 T ...

  2. Vue中MVVM模式的双向绑定原理 和 代码的实现

      今天带大家简单的实现MVVM模式,Object.defineProperty代理(proxy)数据   MVVM的实现方式: 模板编译(Compile) 数据劫持(Observer) Object ...

  3. navcat搜索字符串方法

    navcat搜索字符串方法右键点击数据库 查找字符串即可..

  4. HDU 1723 Distribute Message DP

    The contest’s message distribution is a big thing in prepare. Assuming N students stand in a row, fr ...

  5. SpringBoot 整合RabbitMQ错误记录

    1. 控制台报错:Exception in thread "main" java.io.IOException…… Caused by: com.rabbitmq.client.S ...

  6. java构建树形列表(带children属性)

    一些前端框架提供的树形表格需要手动构建树形列表(带children属性的对象数组),这种结构一般是需要在Java后台构建好. 构建的方式是通过id字段与父id字段做关联,通过递归构建children字 ...

  7. vue 上传进度显示

    参考资料: https://ask.csdn.net/questions/767017 https://www.cnblogs.com/best-fyx/p/11363506.html 我使用的是el ...

  8. Java中级—转发和重定向的区别

    在设计Web应用程序的时候,经常需要把一个系统进行结构化设计,即按照模块进行划分,让不同的Servlet来实现不同的功能,例如可以让其中一个Servlet接收用户的请求,另外一个Servlet来处理用 ...

  9. 【入门篇】前端框架Vue.js知识介绍

    一.Vue.js介绍 1.什么是MVVM? MVVM(Model-View-ViewModel)是一种软件架构设计模式,它源于MVC(Model-View-Controller)模式,它是一种思想,一 ...

  10. OPC 集成的五大要素,你都掌握了吗?

    相信在处理工业项目集成问题的时候,自动化集成供应商真正需要的不是那些华丽的宣传语,而是提供真正的通信数据集成实力. 任何自动化集成的供应商都希望能够消除中间的层层障碍,从而实现真正的信息集成互通.那么 ...