http://newoj.acmclub.cn/problems/2072

题意:给出一个数组a,问对于每一个元素ak有多少个二元组(i,j)满足.

做法:求出p的原根g,然后上面的式子就变成如下形式

即求解有多少对bi+bj等于bk;

这个就好办首先我们队每一个数对P取模,然后得出他的指数,并对指数进行计数。

然后就用快速傅里叶变换,解决这个计数问题。

卷积后面的大于P的需要归入[0,P-1],直接取模循环就可以了。

注意0的情况特殊判断。

PS:在做题过程中原根求错了,抄了个红书的板子

#include "bits/stdc++.h"using namespace std;
const double eps = 1e-6;
#define reg register
#define lowbit(x) x&-x
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first
#define se second
#define makp make_pair
#define cp complex<double>int dcmp(double x) {if (fabs(x) < eps) return 0;return (x > 0) ? 1 : -1;
}typedef long long ll;
typedef unsigned long long ull;
const ull hash1 = 201326611;
const ull hash2 = 50331653;
const ll N = 1100000 + 10;
const int M = 1000000;
const int inf = 0x3f3f3f3f;
const ll mod = 1000000000 + 7;
const double Pi = acos(-1.0);
struct Complex {double x, y;Complex(double xx = 0, double yy = 0) { x = xx, y = yy; }
} a[N], omg[N], inv[N];
ll r[N], cnt = 0;Complex operator+(Complex a, Complex b) { return Complex(a.x + b.x, a.y + b.y); }
Complex operator-(Complex a, Complex b) { return Complex(a.x - b.x, a.y - b.y); }
Complex operator*(Complex a, Complex b) { return Complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }void Cp_init(ll tot, ll lim) {for (int i = 0; i < tot; i++) {omg[i] = Complex(cos(2 * Pi * i / tot), sin(2 * Pi * i / tot));inv[i] = omg[i];inv[i].y *= -1;}for (int i = 0; i < tot; i++) {r[i] = (r[i >> 1] >> 1) | ((i & 1) << (lim - 1));}
}void fft(Complex *a, Complex *omg, ll tot) {for (int i = 0; i < tot; i++) {if (i < r[i]) swap(a[i], a[r[i]]);}for (int l = 2; l <= tot; l <<= 1) {int m = l / 2;for (Complex *p = a; p != a + tot; p += l) {for (int i = 0; i < m; i++) {Complex tmp = omg[tot / l * i] * p[i + m];p[i + m] = p[i] - tmp;p[i] = p[i] + tmp;}}}
}ll quick(ll a, ll n, ll p) {ll ans = 1;while (n) {if (n & 1) ans = ans * a % p;n >>= 1;a = a * a % p;}return ans;
}ll vis[N], n, zero = 0;
ll num[N], xx[N], cont[N], I[N], p, ans[N];vector<ll> gg;
bool g_test(ll g, ll p) {for (ll i = 0; i < gg.size(); i++) {if (quick(g, (p - 1) / gg[i], p) == 1)return 0;}return 1;
}ll p_root(ll p) {ll tmp = p - 1;for (ll i = 2; i <= tmp / i; i++) {if (tmp % i == 0) {gg.push_back(i);while (tmp % i == 0) tmp /= i;}}if (tmp != 1) gg.push_back(tmp);ll g = 1;while (true) {if (g_test(g, p))return g;g++;}
}int main() {scanf("%lld%lld", &n, &p);ll g = p_root(p);///cout << g << endl;ll tt = 1;for (int i = 1; i < p; i++) {tt = tt * g % p;I[tt] = i;}I[1] = 0;for (int i = 0; i < n; i++) {scanf("%lld", &num[i]);xx[i] = num[i] % p;if (xx[i]) cont[I[xx[i]]]++;else zero++;}ll len1 = p - 1;ll lim = 0, tot = 1;while (tot < 2 * len1)tot <<= 1, lim++;for (int i = 0; i < len1; i++) a[i] = Complex(cont[i], 0);for (int i = len1; i < tot; i++) a[i] = Complex(0, 0);Cp_init(tot, lim);fft(a, omg, tot);for (int i = 0; i < tot; i++)a[i] = a[i] * a[i];fft(a, inv, tot);for (int i = 0; i < tot; i++)ans[i] = (ll) (a[i].x / tot + 0.5);for (int i = p - 1; i < tot; i++) ans[i % (p - 1)] += ans[i];ll Zans = 1LL * zero * (zero - 1) + 2LL * zero * (n - zero) + 1LL * zero;for (int i = 0; i < n; i++) {if (num[i] >= p) printf("0\n");else {if (xx[i]) printf("%lld\n", ans[I[xx[i]]]);else printf("%lld\n", Zans);}}return 0;
}

Steins;Gate(原根+FFT)相关推荐

  1. 牛客Steins;Gate(原根+FFT)

    9516: Steins;Gate 时间限制: 2 Sec  内存限制: 128 MB 提交: 33  解决: 10 [提交] [状态] [讨论版] [命题人:admin] 题目描述 助手作为物理学家 ...

  2. steins;gate世界线生成匹配器(结果并没有匹配到)

    用的HTML随机数,但是并没有匹配到我想要的数字 甚至连统计的次数都没有 真的是.. 下次如果有新内容也传到同一文章目录下吧 <!DOCTYPE html> <html>< ...

  3. Mpk文件格式(STEINS;GATE)

    前言 近日看石头门0的动画入迷了,想要入手个游戏来玩玩. 近期steam刚好又有打折活动,不过可惜石头门0只有10%折扣,所以还是以后再买了. 但是石头门打折40%,于是乎又想回顾一下剧情,所以就.. ...

  4. 原根(知识学习+板子总结+例题+应用)

    思路来源 https://baike.baidu.com/item/%E5%8E%9F%E6%A0%B9/8103534?fr=aladdin https://blog.csdn.net/zoro_n ...

  5. HITCON-trainning寒假做题记录

    HITCON-trainning 2019.1.27 是一些好题目这几天准备重新做一遍预计两天之内完成现在做到lab7 题目地址:https://github.com/scwuaptx/HITCON- ...

  6. 华师新生研讨课 课后心得004

    院长这堂课在讲关于计算机概念的出现到发明,涵盖了数字符号.算法与计算机本体三大面向.课堂上对比了欧.亚洲在各面向的发展与由来,而又是因为什么契机在该领域产生了新的突破.而在课堂最后,重新回到了数字符号 ...

  7. 软工大作业·历物语(二)

    文章来源:中国软工亚洲指挥中心(Steins;Gate) 共同作者:纪神,爵爷,老板,小男孩(按首字拼音排序) 责任编辑:爵爷 先大致说一下这两周完成的内容: 登录界面 注册界面 新闻详情界面 用户偏 ...

  8. 软工大作业·历物语(一)

    文章来源:中国软工亚洲指挥中心(Steins;Gate) 共同作者:纪神,爵爷,老板,小男孩(按首字拼音排序) 责任编辑:爵爷 终于开始了正式的开发工作.鉴于团队之前多少有点开发经验,很多界面写起来并 ...

  9. 机器人笔记psv中文_游戏「机器人笔记」、「月英学园」将登陆PSV平台

    "科学ADV系列"第三弹「机器人笔记」将发售PSV版,将于今年冬季发售.声优杉田智和原作游戏「月英学园」的PSV版将于10月10日发售,名为「月英学园-kou-」. 5pb.与Ni ...

最新文章

  1. idea mybatis plugin插件,免费mybatis插件
  2. winformC# TreeView 点击父节点,子节点全选,
  3. Starry Night [USACO]
  4. SpringCloud-容错处理Hystrix熔断器
  5. 一次问卷产品的MVP设计
  6. 通过wifi 连接 adb 到 手机
  7. 基本数据类型float和double的区别
  8. 用作键提取器的函数的 Boost.MultiIndex 示例
  9. 东风日产数据服务有限公司借力服务网格,实现7层流量精细化管控
  10. bootdefault和configuration_springboot常用注解、包引入和自动配置功能解读
  11. 3-8 基于SpringBoot连接数据库与配置MyBatis实操 创建表sql
  12. post postman 传递数组对象_如何使用postman做接口测试
  13. GridView控件常见问题及处理方法
  14. android tab之间滑动切换界面功能
  15. 最全面的AndroidStudio配置指南总结-包括护眼模式
  16. html代码在线高亮美化,代码语法高亮美化显示插件CodeMirror
  17. 通常环境光照度参照表
  18. (P44)面向对象版表达式计算器:符号表SymbolTable的实现
  19. Horner法则(秦九韶算法 )的程序实现
  20. jq多选按钮值_JQuery 多选按钮checkbox

热门文章

  1. AutoComplete(自动完成)
  2. p级数敛散性积分方式证明
  3. Fortran之open,write,read,inquire,Namelist 使用
  4. 两亲性聚合物:Lauric acid PEG Maleimide,Mal-PEG-Lauric acid,月桂酸PEG马来酰亚胺,试剂知识分享
  5. Effie让你优雅的进行创作
  6. CloudBridge服务简单入门
  7. 俄罗斯方块游戏c++代码
  8. 阿里云OSS转移至七牛云存储(详细简洁教程)
  9. 年产5000吨芒果醋工厂设计
  10. ImageGP新上工具:序列提取ID、motif、翻译、反向互补