题目传送门

题目大意

给出一个\(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. request请求《一》

    1. request对象通常用来接收客户端提交到服务端的数据,如:在servlet或者action中可以用request.getParameter()的方法获取获取参数内容: 2. requestSc ...

  2. SpringBoot笔记(4)

    一.请求处理 1.1 常用参数注解使用 注解 使用 @PathVariable 获取URI模板指定请求,并赋值到变量中,不指定可以将所有请求放到map中,但是健值都为String @RequestHe ...

  3. BUUCTF-[极客大挑战 2019]BuyFlag

    BUUCTF-[极客大挑战 2019]BuyFlag 进去一看,哦原来是某安全团队的招募启示. 但没看到什么有用的信息,看到了Q群号,我还以为是一道社工题(=_=) 来到pay.php 看一下源码,发 ...

  4. Shiro03

    1.shiro授权角色.权限 2.Shiro的注解式开发 shiro权限思路 授权 ShiroUserMapper中定义两个方法 // 通过用户ID查询角色 Set<String> get ...

  5. WEB漏洞——XSS

    跨站脚本( Cross-site Scripting,简称为XSS或跨站脚本或跨站脚本攻击)是一种针对网站应用程序的安全漏洞攻击技术,是代码注入的一种. XSS攻击可以分为三种:反射型.存储型和DOM ...

  6. 并发容器之ConcurrentMap

    一.concurentMap 1.数据结构,分段数组segment不扩容,里面的table扩容,每次翻倍,table中放的是entry链表的头地址: 2.初始化 segment和table的长度都是2 ...

  7. 文件流转换(一般用于axios设置接收文件流设置时responseType: 'blob')

    文件流转换 一般用于axios设置接收文件流设置时responseType: 'blob'当接口报错时,前端因已设置responseType: 'blob'无法再接收json格式数据,会把json格式 ...

  8. Vue指令及自定义指令的使用

    导航列表: 一.vue指令 二.自定义指令 一.vue指令 回到顶部    1. v-text v-text主要用来更新textContent,可以等同于JS的text属性,不会解析标签,会把标签解析 ...

  9. matlab函数randperm()

    randperm()会返回一个行向量. 1,randperm(n) 输出一个1×n的矩阵,元素值为1~n的整数,每个元素只出现一次,元素的顺序是随机的. 2,randperm(n,k) 输出一个1×k ...

  10. Insecure CAPTCHA (不安全的验证码)

    dvwa不能正常显示,需要在配置文件中加入谷歌的密钥: $_DVWA[ 'recaptcha_public_key' ] = '6LfX8tQUAAAAAOqhpvS7-b4RQ_9GVQIh48dR ...