Solution -「CF 1380F」Strange Addition
\(\mathcal{Description}\)
Link.
定义两个数在进行加法时,进位单独作为一位。例如:
.
给定一个 \(n\) 为数和 \(m\) 次修改操作,每次修改会修改 \(n\) 位数的某一位数字。在每次修改后求出有多少对数以上述规则相加后的得数为这个 \(n\) 为数。
\(n,m\le5 \times 10^5\)。
\(\mathcal{Solution}\)
显然的 DDP。
令 \(f_i\) 表示加和为目标数后 \(i\) 为数字的数对数量。那么:
\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的更多相关文章
- Solution -「CF 1342E」Placing Rooks
\(\mathcal{Description}\) Link. 在一个 \(n\times n\) 的国际象棋棋盘上摆 \(n\) 个车,求满足: 所有格子都可以被攻击到. 恰好存在 \(k\ ...
- Solution -「CF 1622F」Quadratic Set
\(\mathscr{Description}\) Link. 求 \(S\subseteq\{1,2,\dots,n\}\),使得 \(\prod_{i\in S}i\) 是完全平方数,并最 ...
- Solution -「CF 923F」Public Service
\(\mathscr{Description}\) Link. 给定两棵含 \(n\) 个结点的树 \(T_1=(V_1,E_1),T_2=(V_2,E_2)\),求一个双射 \(\varph ...
- Solution -「CF 923E」Perpetual Subtraction
\(\mathcal{Description}\) Link. 有一个整数 \(x\in[0,n]\),初始时以 \(p_i\) 的概率取值 \(i\).进行 \(m\) 轮变换,每次均匀随机 ...
- Solution -「CF 1586F」Defender of Childhood Dreams
\(\mathcal{Description}\) Link. 定义有向图 \(G=(V,E)\),\(|V|=n\),\(\lang u,v\rang \in E \Leftrightarr ...
- Solution -「CF 1237E」Balanced Binary Search Trees
\(\mathcal{Description}\) Link. 定义棵点权为 \(1\sim n\) 的二叉搜索树 \(T\) 是 好树,当且仅当: 除去最深的所有叶子后,\(T\) 是满的: ...
- Solution -「CF 623E」Transforming Sequence
题目 题意简述 link. 有一个 \(n\) 个元素的集合,你需要进行 \(m\) 次操作.每次操作选择集合的一个非空子集,要求该集合不是已选集合的并的子集.求操作的方案数,对 \(10^9 ...
- Solution -「CF 1023F」Mobile Phone Network
\(\mathcal{Description}\) Link. 有一个 \(n\) 个结点的图,并给定 \(m_1\) 条无向带权黑边,\(m_2\) 条无向无权白边.你需要为每条白边指定边权 ...
- Solution -「CF 599E」Sandy and Nuts
\(\mathcal{Description}\) Link. 指定一棵大小为 \(n\),以 \(1\) 为根的有根树的 \(m\) 对邻接关系与 \(q\) 组 \(\text{LCA}\ ...
随机推荐
- tomcat 可部署4种方式
1.在conf\Catalina\localhost 目录下添加.xml配置文件 2.修改server.xml文件进行部署 3.将项目拷贝到webapps目录下 4.启动tomcat后,打开tomca ...
- 第10组 Alpha冲刺 总结(组长)
1.基本情况 组长博客链接:https://www.cnblogs.com/cpandbb/p/14007413.html 答辩总结: ·产品偏离了最开始的方向,地图和刷一刷功能做得没那么好,外卖订单 ...
- iview 按需引入解决加载慢的问题
如果出现加载2s以上的情况请先查看服务器是否对大文件进行过压缩优化处理. 按照官方文档把iview引入到vue的项目中,全部引入的时候没问题.当按官方文档显示的按需加载是借助插件babel-plugi ...
- IE8和IE9下textarea滚动选中的问题
在IE8和IE9下如果textarea设置了样式overflow-y:auto;就不可以滚动选中了,应该样式写成overflow:auto;有了纵向滚动实际上就不会出现横向滚动的情况,也没有必要ove ...
- PHP代码审计之create_function()函数
0x00 create_function()简介 适用范围:PHP 4> = 4.0.1,PHP 5,PHP 7 功能:根据传递的参数创建匿名函数,并为其返回唯一名称. 语法: 1 create ...
- docker创建mysql容器时挂载文件路径后无法启动(已解决)
系统centos7 docker版本: 解决方法: 在docker run中加入 --privileged=true 给容器加上特定权限,如下 docker run --privileged=tru ...
- MATLAB中回归模型
(1).一元线性回归:数学模型定义 模型参数估计 检验.预测及控制 1.回归模型: 可线性化的一元非线性回归 (2).多元线性回归:数学模型定义 模型参数估计 多元线性回归中检 ...
- MATLAB中插值算法实现
%%%1.M文件%(1).以往少的程序可以在命令行窗口进行编码,但大量的程序编排到命令行窗口,%会有造成乱码的危险.(2).如果将命令编成程序存储在一个文件中(M文件),依次运行文件中的命令,则可以重 ...
- 开发 IDEA Plugin 引入探针,基于字节码插桩获取执行SQL
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 片面了! 一月三舟,托尔斯泰说:"多么伟大的作家,也不过就是在书写自己的片 ...
- STC8H开发(七): I2C驱动MPU6050三轴加速度+三轴角速度检测模块
目录 STC8H开发(一): 在Keil5中配置和使用FwLib_STC8封装库(图文详解) STC8H开发(二): 在Linux VSCode中配置和使用FwLib_STC8封装库(图文详解) ST ...