\(\mathcal{Description}\)

  Link.

  定义两个数在进行加法时,进位单独作为一位。例如:

.

  给定一个 \(n\) 为数和 \(m\) 次修改操作,每次修改会修改 \(n\) 位数的某一位数字。在每次修改后求出有多少对数以上述规则相加后的得数为这个 \(n\) 为数。

  \(n,m\le5 \times 10^5\)。

\(\mathcal{Solution}\)

  显然的 DDP。

  令 \(f_i\) 表示加和为目标数后 \(i\) 为数字的数对数量。那么:

\[ w_{i+1}
\begin{pmatrix}
f_i\\
f_{i-1}
\end{pmatrix}
=
\begin{pmatrix}
f_{i+1}\\
f_i
\end{pmatrix}
\]

  其中 \(w_i~(i=1,2,\dots,18)\) 分别表示每种“一位数”的转移矩阵,只有 \(i=1\) 需要特殊处理。

  具体看代码吧(摊手。

\(\mathcal{Code}\)

/* Clearink */

#include <cstdio>

inline int rint () {
int x = 0, f = 1; char s = getchar ();
for ( ; s < '0' || '9' < s; s = getchar () ) f = s == '-' ? -f : f;
for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
return x * f;
} template<typename Tp>
inline void wint ( Tp x ) {
if ( x < 0 ) putchar ( '-' ), x = ~ x + 1;
if ( 9 < x ) wint ( x / 10 );
putchar ( x % 10 ^ '0' );
} const int MAXN = 5e5, MOD = 998244353;
const int w[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int n, m;
char num[MAXN + 5]; inline int add ( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
inline int mul ( long long a, const int b ) { return ( a *= b ) < MOD ? a : a % MOD; } struct Matrix {
int mat[2][2];
Matrix (): mat {} {}
Matrix ( const int a, const int b, const int c, const int d ):
mat { a, b, c, d } {} inline int* operator [] ( const int key ) { return mat[key]; } inline Matrix operator * ( Matrix& t ) const {
Matrix ret;
for ( int i = 0; i < 2; ++ i ) {
for ( int k = 0; k < 2; ++ k ) {
for ( int j = 0; j < 2; ++ j ) {
ret[i][j] = add ( ret[i][j], mul ( mat[i][k], t[k][j] ) );
}
}
}
return ret;
} inline void _show () const {
#ifdef RYBY
for ( int i = 0; i < 2; ++ i ) {
for ( int j = 0; j < 2; ++ j ) {
printf ( "%d ", mat[i][j] );
}
putchar ( '\n' );
}
#endif
}
}; inline Matrix digit ( const int d ) {
return Matrix ( w[num[d] - '0'], num[d] ^ '1' || d == n ? 0 : w[10 + num[d + 1] - '0'], 1, 0 );
} struct SegmentTree {
Matrix mat[MAXN * 2 + 5]; inline int id ( const int l, const int r ) { return ( l + r ) | ( l != r ); } inline int build ( const int l, const int r ) {
int rt = id ( l, r ), mid = l + r >> 1;
if ( l == r ) return ( mat[rt] = digit ( l ) )._show (), rt;
int lc = build ( l, mid ), rc = build ( mid + 1, r );
return mat[rt] = mat[lc] * mat[rc], rt;
} inline void update ( const int l, const int r, const int x, const char d ) {
int rt = id ( l, r ), mid = l + r >> 1;
if ( l == r ) return num[l] = d, mat[rt] = digit ( l ), void ();
if ( x <= mid ) update ( l, mid, x, d );
else update ( mid + 1, r, x, d );
mat[rt] = mat[id ( l, mid )] * mat[id ( mid + 1, r )];
}
} segt; int main () {
n = rint (), m = rint ();
scanf ( "%s", num + 1 );
int rt = segt.build ( 1, n );
for ( int x, d; m --; ) {
x = rint (), d = rint ();
segt.update ( 1, n, x, d ^ '0' );
if ( x > 1 ) segt.update ( 1, n, x - 1, num[x - 1] );
segt.mat[rt]._show ();
wint ( segt.mat[rt][0][0] ), putchar ( '\n' );
}
return 0;
}

Solution -「CF 1380F」Strange Addition的更多相关文章

  1. Solution -「CF 1342E」Placing Rooks

    \(\mathcal{Description}\)   Link.   在一个 \(n\times n\) 的国际象棋棋盘上摆 \(n\) 个车,求满足: 所有格子都可以被攻击到. 恰好存在 \(k\ ...

  2. Solution -「CF 1622F」Quadratic Set

    \(\mathscr{Description}\)   Link.   求 \(S\subseteq\{1,2,\dots,n\}\),使得 \(\prod_{i\in S}i\) 是完全平方数,并最 ...

  3. Solution -「CF 923F」Public Service

    \(\mathscr{Description}\)   Link.   给定两棵含 \(n\) 个结点的树 \(T_1=(V_1,E_1),T_2=(V_2,E_2)\),求一个双射 \(\varph ...

  4. Solution -「CF 923E」Perpetual Subtraction

    \(\mathcal{Description}\)   Link.   有一个整数 \(x\in[0,n]\),初始时以 \(p_i\) 的概率取值 \(i\).进行 \(m\) 轮变换,每次均匀随机 ...

  5. Solution -「CF 1586F」Defender of Childhood Dreams

    \(\mathcal{Description}\)   Link.   定义有向图 \(G=(V,E)\),\(|V|=n\),\(\lang u,v\rang \in E \Leftrightarr ...

  6. Solution -「CF 1237E」Balanced Binary Search Trees

    \(\mathcal{Description}\)   Link.   定义棵点权为 \(1\sim n\) 的二叉搜索树 \(T\) 是 好树,当且仅当: 除去最深的所有叶子后,\(T\) 是满的: ...

  7. Solution -「CF 623E」Transforming Sequence

    题目 题意简述   link.   有一个 \(n\) 个元素的集合,你需要进行 \(m\) 次操作.每次操作选择集合的一个非空子集,要求该集合不是已选集合的并的子集.求操作的方案数,对 \(10^9 ...

  8. Solution -「CF 1023F」Mobile Phone Network

    \(\mathcal{Description}\)   Link.   有一个 \(n\) 个结点的图,并给定 \(m_1\) 条无向带权黑边,\(m_2\) 条无向无权白边.你需要为每条白边指定边权 ...

  9. Solution -「CF 599E」Sandy and Nuts

    \(\mathcal{Description}\)   Link.   指定一棵大小为 \(n\),以 \(1\) 为根的有根树的 \(m\) 对邻接关系与 \(q\) 组 \(\text{LCA}\ ...

随机推荐

  1. spring boot & maven 多模块 ---心得

    1.前言 有个名字叫 多模块企业级项目  ,其实就是一个父级maven工程里面有着多个子级maven工程的项目 ,甚至在子级maven 里面还有多个子级maven, 这用到了 maven多模块开发的使 ...

  2. Hive与MapReduce相关排序及自定义UDF函数

    原文链接: https://www.toutiao.com/i6770870821809291788/ Hive和mapreduce相关的排序和运行的参数 1.设置每个reduce处理的数据量(单位是 ...

  3. Collection中的常用方法

    1:往集合中添加元素 boolean add(Object o);2:获取集合中元素的个数 int size();3:boolean contains(Object o) 判断集合是否包含元素o4:清 ...

  4. 简单的Dos 命令

    1.1.如何操作DOS命令 开始---运行---输入cmd--回车 或者 Win + R ---运行---输入cmd--回车 1.2.基本命令 1. 命令:color f0 帮助:color ? 作用 ...

  5. 使用Kubernetes两年来的7大经验教训

    来源:分布式实验室译者:冯旭松在Ridecell公司管理基础设施团队几年后,我想在停下来休息时记录一些想法和经验教训. 1Kubernetes不仅仅是炒作 我在Kubernetes领域里活跃了很久,所 ...

  6. 一键AI着色,黑白老照片画面瞬间鲜活

    很多老照片或者电影受时代技术所限制,只能以黑白形式保存:经过编辑后的黑白视频和图片早已丢失彩色原图,这对于保存者来说都十分遗憾.如何能将单一乏味.陈旧斑驳的黑白照片变成鲜活亮丽的彩色照片,从照片中重新 ...

  7. linux开放端口关闭防火墙

    linux开放端口关闭防火墙 systemctl status firewalld查看当前防火墙状态. 开启防火墙      systemctl start firewalld开放指定端口       ...

  8. leetcode 509. 斐波那契数

    问题描述 斐波那契数,通常用 F(n) 表示,形成的序列称为斐波那契数列.该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和.也就是: F(0) = 0,   F(1) = 1 F(N) ...

  9. 浅谈 Java 多线程(一) --- JMM

    为什么使用多线程 更多的处理器核心数(硬件的发展使 CPU 趋向于更多的核心数,如果不能充分利用,就无法显著提升程序的效率) 更快的响应时间(复杂的业务场景下,会存在许多数据一致性不强的操作,如果将这 ...

  10. IDEA2017 maven Spark HelloWorld项目(本地断点调试)

    作为windows下的spark开发环境 1.应用安装 首先安装好idea2017 java8 scalaJDK spark hadoop(注意scala和spark的版本要匹配) 2.打开idea, ...