Description

Link.

给出一个长度为 \(n\) 的序列 \(a\),问有序三元组 \((a_{i},a_{j},a_{k})\) 使得 \(i\neq j\neq k\) 且 \(a_{i}+a_{j}=a_{k}\) 的数量。

Solution

发现这个值域有说头,于是设 \(F(x)=\sum_{i=1}^{n}x^{a_{i}}\)。

然后求出 \(F^{2}(x)\),判断一通就好了。

主要是记录一下这种多项式题的常用 trick,把值域小的整成多项式或者生成函数一类的。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
namespace Poly
{
typedef complex<double> comp;
typedef vector<complex<double> > poly;
#define len(x) (LL((x).size()))
const double bh_pi=acos(-1);
LL lim,rev[400010];
void fft(poly &f,LL op)
{
for(LL i=0;i<lim;++i) if(i<rev[i]) swap(f[i],f[rev[i]]);
for(LL len=2;len<=lim;len<<=1)
{
comp bas(cos(2*bh_pi/len),op*sin(2*bh_pi/len));
for(LL fr=0;fr<lim;fr+=len)
{
comp now(1,0);
for(LL ba=fr;ba<fr+(len>>1);++ba,now*=bas)
{
comp tmp=now*f[ba+(len>>1)];
f[ba+(len>>1)]=f[ba]-tmp;
f[ba]+=tmp;
}
}
}
if(op==-1) for(LL i=0;i<lim;++i) f[i]/=lim;
}
poly mulself(poly f)
{
LL n=(len(f)<<1)-1; lim=1;
while(lim<n) lim<<=1;
for(LL i=0;i<lim;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(lim>>1):0);
f.resize(lim),fft(f,1);
for(LL i=0;i<lim;++i) f[i]*=f[i];
fft(f,-1),f.resize(n);
return f;
}
}using namespace Poly;
LL n,mx,nzr,tmp[400010],a[400010],ans;
const LL lay=50000;
int main()
{
scanf("%lld",&n);
poly f(100001);
for(LL i=1,x;i<=n;++i)
{
scanf("%lld",&x);
mx=max(mx,lay+x);
f[lay+x]=comp(f[lay+x].real()+1,0);
nzr+=(x==0),a[i]=x;
}
++mx;
f.resize(mx);
f=mulself(f);
for(LL i=0;i<len(f);++i) tmp[i]=LL(f[i].real()+0.49);
for(LL i=1;i<=n;++i) --tmp[(lay+a[i])<<1];
for(LL i=1;i<=n;++i)
{
ans+=tmp[a[i]+(lay<<1)];
if(a[i]) ans-=(nzr<<1);
else ans-=((nzr-1)<<1);
}
printf("%lld\n",ans);
return 0;
}

Solution -「香港网络赛 2016」A+B Problem的更多相关文章

  1. 2016 acm香港网络赛 A题. A+B Problem (FFT)

    原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/arch ...

  2. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem

    Let SS be a sequence of integers s_{1}s​1​​, s_{2}s​2​​, ......, s_{n}s​n​​Each integer is is associ ...

  3. 2016 acm香港网络赛 C题. Classrooms(贪心)

    原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...

  4. 2016 acm香港网络赛 F题. Crazy Driver(水题)

    原题网址:https://open.kattis.com/problems/driver Crazy Driver In the Linear City, there are N gates arra ...

  5. 2016 acm香港网络赛 B题. Boxes

    原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N ...

  6. Solution -「NOI 模拟赛」彩色挂饰

    \(\mathcal{Description}\)   给定一个含 \(n\) 个点 \(m\) 条边的简单无向图,设图中最大点双的大小为 \(s\),则保证 \(s\le6\).你将要用 \(k\) ...

  7. Solution -「NOI 模拟赛」出题人

    \(\mathcal{Description}\)   给定 \(\{a_n\}\),求一个 \(\{b_{n-1}\}\),使得 \(\forall x\in\{a_n\},\exists i,j\ ...

  8. Solution -「树上杂题?」专练

    主要是记录思路,不要被刚开始错误方向带偏了 www 「CF1110F」Nearest Leaf 特殊性质:先序遍历即为 \(1 \to n\),可得出:叶子节点编号递增或可在不改变树形态的基础上调整为 ...

  9. Solution -「SV 2020 Round I」SA

    \(\mathcal{Description}\)   求出处 owo.   给定一个长度为 \(n\),仅包含小写字母的字符串 \(s\),问是否存在长度为 \(n\),仅包含小写字母的字符串 \( ...

  10. Solution -「SV 2020 Round I」「SRM 551 DIV1」「TC 12141」SweetFruits

    \(\mathcal{Description}\)   link.   给定 \(n\) 个水果,每个结点可能有甜度 \(v_i\),或不甜(\(v_i=-1\)).现在把这些水果串成一棵无根树.称一 ...

随机推荐

  1. 解决org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource **/**/dao/**Mapper.xml问题

    1. 问题分析 出现此问题的原因是资源过滤的问题,编写在DAO包中的XML文件没有被打包. 2. 解决方案 在pom.xml文件中加入如下资源过滤: <!-- 静态资源导出问题 --> & ...

  2. Devexpress如何获取RadioGroup选中项的值和显示值

    分享一个小技巧,如题目所示,DEV控件如何获取RadioGroup选中项的值和显示值.也是在网上找了很久,看了大家都是通过SelectIndex的值定位选中的按钮,并没有说取选中项的值,所以自己研究了 ...

  3. 前端vue地图定位并测算当前定位离目标位置距离可用于签到打卡

    前端vue地图定位并测算当前定位离目标位置距离可用于签到打卡, 下载完整代码请访问uni-app插件市场地址: https://ext.dcloud.net.cn/plugin?id=12974 效果 ...

  4. 记录一个在写项目中遇到的Maven依赖无法导入的问题

    记录一个在写项目中遇到的Maven依赖无法导入的问题 项目是一个父项目做依赖管理,三个子项目,今天遇到一个问题: 子项目中导入的依赖,怎么都导入不进去,maven仓库中已经有了,idea提示也没有问题 ...

  5. ThinkPHP6.0 链式SQL语句

    ThinkPHP6.0 链式SQL语句 查询单个数据 $user = Db::query('select * from `user`'); $user=Db::table('user')->wh ...

  6. 怎样优雅地增删查改(一):从0开始搭建Volo.Abp项目

    @ 目录 项目介绍 模块化 由框架实现的 需要实现的 创建项目 创建业务模块 配置引用和依赖 配置DbContext 创建实体和Dto 配置AutoMapper 软件系统中数据库或者持久层的基本操作功 ...

  7. 运行C时报错:relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain‘ collect2: error

    写C时,遇到报错 [Running] cd "d:\考研\408\LeranC\Code\GramForC\" && gcc 01data_types.c -o 0 ...

  8. 2023-07-19:布尔表达式 是计算结果不是 true 就是 false 的表达式 有效的表达式需遵循以下约定: ‘t‘,运算结果为 true ‘f‘,运算结果为 false ‘!(subExpr

    2023-07-19:布尔表达式 是计算结果不是 true 就是 false 的表达式 有效的表达式需遵循以下约定: 't',运算结果为 true 'f',运算结果为 false '!(subExpr ...

  9. Nginx TCP 负载均衡:stream 模块配置

    工作上遇到需要用nginx做负载均衡,参考了前同事留下的作业顺利搞定,感觉这块很有意义写篇文档记录. 参考:nginx tcp负载均衡(Stream模块)配置说明 参考:利用nginx进行TCP负载均 ...

  10. Linux 命令:find/grep/sed/awk/du/df

    目录 find grep sed awk du/df find # find 属于全部匹配,如输入abc,不能查到abcd # find 默认采用递归搜索 # 按时间 find . -atime -1 ...