题目传送门

题目大意

给出一个\(n\)个数的序列\(a_{1,2,..,n}\),可以选\(n\)次,每次可以选与上次选的相同的数,问对于\(\forall p\in[0,n-1]\)满足选出来的数进行十进制不进位加法结果为\(p\)的方案数。答案对\(2^{58}\)取模。

思路

乍一看,这是一道\(k=10\)的\(k\)进制\(\text {FWT}\)的板题。但是,我们发现这个模数十分的神仙,于是我们就需要解决下面两个问题:

  • 如何求出\(10^5\)的逆元

  • 如何求出模\(2^{58}\)意义下的\(w_{10}\)

似乎第一个问题比较好解决一点。这里解释一下为什么是除以\(10^5\),本来逆运算的时候应该除以\(10\),但是我们为了方便可以先不除,最后一起除。

我们发现\(5\)在模\(2^{58}\)意义下是有逆元的,于是我们的问题就是如何求出\(2^5\)的逆元。我们可以先求出模\(2^{64}\)下的答案,然后我们发现直接除以\(2^5\)就是答案了。

于是,我们发现模\(2^{64}\)其实就是\(\text {unsigned long long}\)自然溢出。

我们现在需要解决第二个问题。我们发现这个无理数不可能在\(2^{58}\)有对应的数。而我们现在又发现\(w_{10}^5=w_2=-1\)模\(2^{64}\),于是,我们可以设\(x=w_{10}\),于是我们可以用多项式来表示,最后的答案就是对\(x^5+1\)取模。

于是我们只需要考虑如何把一个多项式转换成整数。我们发现模\(x^5+1\)实际上就等价于模\(1-x+x^2-x^3+x^4\)。而我们发现最后的答案其实就是常数项。

于是,我们就在\(\Theta(2500n\log n)\)的时间复杂度解决了这个问题。

细节

  • \(\forall 5\le a\le 8,x^a\equiv -x^{a\bmod 5}(\bmod x^5+1)\)

  • \([x^0](a_0x^0+a_1x^1+a_2x^2+a_3x^3+a_4x^4)\equiv a_0-a_1(\bmod 1-x+x^2-x^3+x^4)\)

\(\text {Code}\)

#include <bits/stdc++.h>
using namespace std; #define ull unsigned long long
#define Int register int
#define MAXN 400005
#define lim 100000 template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');} int n;
ull inv = 6723469279985657373ull; struct Poly{
ull a[5];
Poly(){a[0] = a[1] = a[2] = a[3] = a[4] = 0;}
Poly operator + (Poly p){
Poly res;
for (Int i = 0;i < 5;++ i) res.a[i] = a[i] + p.a[i];
return res;
}
Poly operator * (Poly p){
ull tmp[10];Poly res;
memset (tmp,0,sizeof (tmp));
for (Int i = 0;i < 5;++ i)
for (Int j = 0;j < 5;++ j)
tmp[i + j] += a[i] * p.a[j];
for (Int i = 0;i < 5;++ i) res.a[i] = tmp[i] - tmp[i + 5];
return res;
}
ull Turn (){
ull tmp = a[1];for (Int i = 0;i < 5;++ i) a[i] -= tmp;
tmp = a[2];for (Int i = 0;i < 5;i += 2) a[i] -= tmp;
return a[0];
}
}ans[MAXN],bas[10],zero; Poly quick_pow (Poly a,int b){
Poly res;memset (res.a,0,sizeof (res.a)),res.a[0] = 1;
for (;b;b >>= 1,a = a * a) if (b & 1) res = res * a;
return res;
} void FWT (Poly *a,int type){
int id[10];Poly b[10];
for (Int len = 1;len < lim;len *= 10)
for (Int i = 0;i < lim;i += len * 10)
for (Int j = 0;j < len;++ j){
for (Int d = 0;d < 10;++ d){
id[d] = i + j + d * len;
b[d] = a[id[d]],a[id[d]] = zero;
}
for (Int d = 0;d < 10;++ d)
for (Int e = 0;e < 10;++ e)
a[id[d]] = a[id[d]] + bas[(10 + type) * d * e % 10] * b[e];
}
} signed main(){
read (n);
for (Int i = 1,a;i <= n;++ i) read (a),++ ans[a].a[0];
for (Int i = 0;i < 10;++ i) bas[i].a[i % 5] = i >= 5 ? -1 : 1;
FWT (ans,1);
for (Int i = 0;i < lim;++ i) ans[i] = quick_pow (ans[i],n);
FWT (ans,-1);
for (Int i = 0;i < n;++ i) write (((ans[i].Turn() * inv) >> 5) % (1ull << 58)),putchar ('\n');
return 0;
}

参考博客

https://www.luogu.com.cn/blog/foreverlasting/solution-cf1103e

https://www.cnblogs.com/Mr-Spade/p/10390667.html

https://memset0.cn/cf1103e

https://www.luogu.com.cn/blog/command-block/wei-yun-suan-juan-ji-yu-ji-kuo-zhan

题解 CF1103E Radix sum的更多相关文章

  1. [cf1103E]Radix sum

    类似于uoj272,即$B=10$的情况,然后有以下几个细节问题: 1.答案对$2^{58}$取模可以先使用自然溢出模$2^{64}$,最后对$2^{58}$取模即可 2.为了避免实数,令$\omeg ...

  2. [LeetCode 题解]:Path Sum

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a bi ...

  3. LeetCode题解39.Combination Sum

    39. Combination Sum Given a set of candidate numbers (C) (without duplicates) and a target number (T ...

  4. Codeforces 1103 E. Radix sum

    题目链接 神题. 题意:给定一个长度为\(10^5\)的幂级数\(a\),将卷积的下标运算定义为十进制下的不进位加法,求\(a^k\)模\(2^{58}\)的结果.\(k\leq 10^9\). 题解 ...

  5. PAT甲题题解-1081. Rational Sum (20)-模拟分数计算

    模拟计算一些分数的和,结果以带分数的形式输出注意一些细节即可 #include <iostream> #include <cstdio> #include <algori ...

  6. 《LeetBook》LeetCode题解(1) : Two Sum[E]——哈希Map的应用

    001.Two Sum[E] Two SumE 题目 思路 1双重循环 2 排序 3 Hashmap 1.题目 Given an array of integers, return indices o ...

  7. [题解] CF622F The Sum of the k-th Powers

    CF622F The Sum of the k-th Powers 题意:给\(n\)和\(k\),让你求\(\sum\limits_{i = 1} ^ n i^k \ mod \ 10^9 + 7\ ...

  8. 题解 CF920F 【SUM and REPLACE】

    可以事先打表观察每个数的约数个数,观察到如果进行替换,若干次后这个数便会被替换成1. 所以我们可以直接暴力的进行区间修改,若这个数已经到达1或2,则以后就不再修改,用并查集和树状数组进行维护. 这个方 ...

  9. LeetCode 题解之 Two Sum

    1.题目描述 2.问题分析 使用hashTable 寻找,target  -  num[i] ,将时间复杂度降低到 O(n): 3.代码 vector<int> twoSum(vector ...

随机推荐

  1. C# - 音乐小闹钟_BetaV1.0

    时间:2017-11-20 作者:byzqy 介绍: 前段时间看到别人利用Timer控件实现了检查电脑本地时间,然后对时间进行比较,最终实现闹钟功能.感觉有点意思,于是自己也做了一个小闹钟! 先看一下 ...

  2. 为什么Class实例可以不是全局唯一的——自定义类加载器

    为什么Class实例可以不是全局唯一的 通过定义两个类加载器加载同一字节码文件来证明Class实例为什么不是全局唯一的 1.将一个名为Demo(没有后缀)的字节码文件放在D盘根目录 2.定义两个类加载 ...

  3. 手写AVL平衡二叉搜索树

    手写AVL平衡二叉搜索树 二叉搜索树的局限性 先说一下什么是二叉搜索树,二叉树每个节点只有两个节点,二叉搜索树的每个左子节点的值小于其父节点的值,每个右子节点的值大于其左子节点的值.如下图: 二叉搜索 ...

  4. linux 性能统计命令

    命令1 性能压力测试,yes持续输出30s到设备中空文件,然后杀掉进程 { yes> /dev/null & } && sleep 30 && ps -e ...

  5. java版gRPC实战之二:服务发布和调用

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  6. 任由文字肆意流淌,更自由的开源 Markdown 编辑器

    对于创作平台来说内容编辑器是十分重要的功能,强大的编辑器可以让创作者专注于创作"笔"下生花.而最好取悦程序员创作者的方法之一就是支持 Markdown 写作,因为大多数程序员都是用 ...

  7. 在windows中给git修改默认的编辑器为sublime

    首先,需要配置sublime的为环境变量,这是为了让git能通过命令调用sublime.也可以写一个.bat脚本.然后,让git调用bat脚本也可以 配置环境变量path到subl.exe的目录 脚本 ...

  8. Elasticsearch(ES)的高级搜索(DSL搜索)(下篇)

    1. 概述 之前聊了Elasticsearch(ES)的高级搜索(DSL搜索)的一部分内容,今天把剩下的部分聊完. 2. 场景说明 2.1 创建索引同时创建映射 PUT  http://192.168 ...

  9. git实战-linux定时监控github更新状态(二)

    系列文章 git介绍-常用操作(一)✓ git实战-linux定时监控github更新状态(二)✓ 本文主要内容 如何查看github的本地仓库和远程仓库的同步情况 linux服务器定时监控githu ...

  10. mysql5.7执行sql语句提示Expression #1 of ORDER BY clause is not in GROUP BY

    mysql 新版本出现group by 语句不兼容问题 [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause ...