题目传送门

题目大意

给出一个\(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. Mysql You can't specify target table 'newsalrecord' for update in FROM clause

    这个问题是不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值.解决办法就是建立个临时的表.

  2. 对于MySQL远程连接中出现的一个问题总结

    2021年9月3日更新补充 (真的心累,本来是个小问题,但是网上帖子都基本差不多,基本都是相同的操作,导致搜了半个多小时才解决) 一.首先为什么要重新发一次呢,因为我发现上次写的这个记录是不完善甚至是 ...

  3. vue 输入框禁止输入空格 ,只能输入数字,禁止输入数字

    正则表达式: @input="form.userName = form.userName.replace(/\s+/g,'')"    ( 禁止输入空格)    @input=&q ...

  4. JS_DOM操作之常用事件

    1 - onload 事件:加载完成后立即执行 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  5. SAR总结

    1.星载InSAR技术简介 星载合成孔径雷达干涉测量(InSAR)是一种用于大地测量和遥感的雷达技术.InSAR使用两个或多个SAR图像,利用返回卫星的波的相位差来计算目标地区的地形.地貌以及表面的微 ...

  6. 《openssl编程》:第一章基础知识

    第一章 基础知识 1.1 对称算法 对称算法使用一个密钥.给定一个明文和一个密钥,加密产生密文,其长度和明文大致相同.解密时,使用读密钥与加密密钥相同. 对称算法主要有四种加密模式: (1) 电子密码 ...

  7. 基于Ubuntu18.04一站式部署(python-mysql-redis-nginx)

    基于Ubuntu18.04一站式部署 Python3.6.8的安装 1. 安装依赖 ~$ sudo apt install openssl* zlib* 2. 安装python3.6.8(个人建议从官 ...

  8. Delphi使用Zxing创建二维码

    效果 DelphiZXingQRCode下载地址:https://www.debenu.com/open-source/delphizxingqrcode/ 为了调用方便unit DelphiZXIn ...

  9. TCP协议和套接字

    一.TCP通信概述,逻辑连接就是三次握手 二.客户端和服务端实现TCP协议通信基本步骤 1.客户端套接字对象 Socket 2.服务端套接字ServerSocket 客户端补充完整代码:除了创建各自的 ...

  10. linux 档案权限篇之一

    一:预备知识 1.在linux中,任何一个档案都具有.所有者.用户组.其他用户这三种身份的个别权限. 1.所有者:即档案拥有者,由于Linux是多人多任务的系统,因此可能常常会有很多人同时使用这部主机 ...