Description

大家应该都读过题。

Solution

赛后变摩托。

我们对每一个操作 \(3\) 连边建图,然后可以知道只是一个 \(\texttt{DAG}\)。

考虑操作 \(2\),我们只需要最后计算即可。

现在来看加法操作。我们设我们当前的操作为 \(a_{p}\leftarrow a_{p}+v\),后面一共有 \(k\) 个乘法操作,我们设为分别让序列整体乘上 \(b_{1,2,\cdots,k}\)。那么 \(a_{p}\leftarrow a_{p}+v\) 一共会对最后的 \(a_{p}\) 产生 \(v\times\prod_{i=1}^{k}b_{i}\) 的贡献。

于是我们可以把操作离线下来,倒着来处理。

那么最后来考虑操作 \(3\),我们来看操作 \(3\) 连出的图。

对于图上的每一个节点我们维护一个值,表示执行后会带来的系数。

那么和操作 \(1\) 类似的,我们对整张图进行拓扑,然后倒着处理,处理出每个节点的操作的加法计算了多少次,然后传播(指所有相邻节点)到加法操作的节点。

最后处理原序列即可。

(代码从 \(\texttt{Vim}\) 里面复制出来可能缩进有问题)

#include <queue>
#include <cstdio>
#define mod ( 998244353 ) using namespace std;
typedef long long LL; const int MAXN = 1e6 + 5; template<typename _T>
void read( _T &x ){
x = 0; char c = getchar(); _T f = 1;
while( c < '0' || c > '9' ){ if( c == '-' ) f = -1; c = getchar(); }
while( c >= '0' && c <= '9' ){ x = ( x << 3 ) + ( x << 1 ) + ( c & 15 ); c = getchar(); }
x *= f;
} template<typename _T>
void write( _T x ){
if( x < 0 ){ putchar( '-' ); x = -x; }
if( x > 9 ) write( x / 10 );
putchar( x % 10 + '0' );
} struct starS{
int to, nxt;
starS( int T = 0, int N = 0 ){ to = T; nxt = N; }
} as[MAXN * 2]; struct operateS{
int Tp, pos;
LL add, mul, sum;
operateS( int T = 0, int P = 0, LL A = 0, LL M = 0, LL S = 0 ){ Tp = T; pos = P; add = A; mul = M; sum = S; }
} opS[MAXN]; int N, M, Q;
int totE, totT;
int A[MAXN], topS[MAXN], degS[MAXN], firS[MAXN], queS[MAXN]; void pushEdge( int u, int v ){ as[++ totE] = starS( v, firS[u] ); firS[u] = totE; } void TopSort( ){
queue<int> align;
for( int i = 1; i <= M; ++ i ){
if( ! degS[i] ) align.push( i );
}
while( ! align.empty( ) ){
int u = align.front( ); align.pop( );
topS[++ totT] = u;
for( int i = firS[u]; i; i = as[i].nxt ){
int v = as[i].to; degS[v] --;
if( ! degS[v] ) align.push( v );
}
}
} int main( ){
read( N );
for( int i = 1; i <= N; ++ i ) read( A[i] );
read( M );
for( int i = 1; i <= M; ++ i ){
read( opS[i].Tp );
if( opS[i].Tp == 1 ){
read( opS[i].pos ); read( opS[i].add );
opS[i].mul = 1;
}
else if( opS[i].Tp == 2 ) {
read( opS[i].mul );
opS[i].add = opS[i].mul;
}
else{
read( opS[i].pos );
opS[i].mul = 1;
for( int j = 1, to; j <= opS[i].pos; ++ j ){ read( to ); pushEdge( i, to ); degS[to] ++; }
}
}
TopSort( );
for( int i = M; i; -- i ){
int u = topS[i];
for( int j = firS[u]; j; j = as[j].nxt ){
int v = as[j].to;
opS[u].mul = ( LL )opS[u].mul * opS[v].mul % mod;
}
}
read( Q ); int now = 1;
for( int i = 1; i <= Q; ++ i ) read( queS[i] );
for( int i = Q; i; -- i ){ opS[queS[i]].sum = ( ( LL )opS[queS[i]].sum + now ) % mod; now = ( LL )now * opS[queS[i]].mul % mod; }
for( int i = 1; i <= M; ++ i ){
int u = topS[i], now = 1;
for( int j = firS[u]; j; j = as[j].nxt ){
int v = as[j].to;
opS[v].sum = ( ( LL )opS[u].sum * now % mod + opS[v].sum ) % mod;
now = ( LL )now * opS[v].mul % mod;
}
}
for( int i = 1; i <= N; ++ i ) A[i] = ( LL )A[i] * now % mod;
for( int i = 1; i <= M; ++ i ){
if( opS[i].Tp == 1 ) A[opS[i].pos] = ( A[opS[i].pos] + ( LL )opS[i].add * opS[i].sum % mod ) % mod;
}
for( int i = 1; i <= N; ++ i ) write( A[i] ), putchar( ' ' );
return 0;
}

Solution -「CSP-S 2020」函数调用的更多相关文章

  1. Solution -「多校联训」排水系统

    \(\mathcal{Description}\)   Link.   在 NOIP 2020 A 的基础上,每条边赋权值 \(a_i\),随机恰好一条边断掉,第 \(i\) 条段的概率正比于 \(a ...

  2. Note/Solution -「洛谷 P5158」「模板」多项式快速插值

    \(\mathcal{Description}\)   Link.   给定 \(n\) 个点 \((x_i,y_i)\),求一个不超过 \(n-1\) 次的多项式 \(f(x)\),使得 \(f(x ...

  3. Solution -「洛谷 P4198」楼房重建

    \(\mathcal{Description}\)   Link.   给定点集 \(\{P_n\}\),\(P_i=(i,h_i)\),\(m\) 次修改,每次修改某个 \(h_i\),在每次修改后 ...

  4. Solution -「洛谷 P6577」「模板」二分图最大权完美匹配

    \(\mathcal{Description}\)   Link.   给定二分图 \(G=(V=X\cup Y,E)\),\(|X|=|Y|=n\),边 \((u,v)\in E\) 有权 \(w( ...

  5. Solution -「多校联训」I Love Random

    \(\mathcal{Description}\)   给定排列 \(\{p_n\}\),可以在其上进行若干次操作,每次选取 \([l,r]\),把其中所有元素变为原区间最小值,求能够得到的所有不同序 ...

  6. Solution -「多校联训」签到题

    \(\mathcal{Description}\)   Link.   给定二分图 \(G=(X\cup Y,E)\),求对于边的一个染色 \(f:E\rightarrow\{1,2,\dots,c\ ...

  7. Solution -「多校联训」朝鲜时蔬

    \(\mathcal{Description}\)   Link.   破案了,朝鲜时蔬 = 超现实树!(指写得像那什么一样的题面.   对于整数集 \(X\),定义其 好子集 为满足 \(Y\sub ...

  8. Solution -「多校联训」消失的运算符

    \(\mathcal{Description}\)   Link.   给定长度为 \(n\) 的合法表达式序列 \(s\),其中数字仅有一位正数,运算符仅有 - 作为占位.求将其中恰好 \(k\) ...

  9. Solution -「多校联训」假人

    \(\mathcal{Description}\)   Link.   一种物品有 长度 和 权值 两种属性,现给定 \(n\) 组物品,第 \(i\) 组有 \(k_i\) 个,分别为 \((1,a ...

  10. Solution -「多校联训」古老的序列问题

    \(\mathcal{Description}\)   Link.   给定序列 \(\{a_n\}\),和 \(q\) 次形如 \([L,R]\) 的询问,每次回答 \[\sum_{[l,r]\su ...

随机推荐

  1. 搭建springbootweb环境

    搭建springboot环境(idea环境) 实现步骤: 1.基础环境配置 2.maven配置 3.编写第一个程序helloworld(可能有两个小问题) 4.运行(jar包运行,命令行运行) 一.基 ...

  2. 【C++ Primer】第二章(2 ~ 6节)

    变量 变量提供一个具名的.可供程序操作的存储空间. C++中变量和对象一般可以互换使用. 变量定义(define) 定义形式:类型说明符(type specifier) + 一个或多个变量名组成的列表 ...

  3. CF1034D Intervals of Intervals

    简要题意 给定 \(n\) 个区间组成的序列,定义它的一个连续段的价值为这个段内所有区间的并覆盖的长度.求价值前 \(k\) 大的段的价值和. 数据范围:\(1\le n\le 3\times 10^ ...

  4. OOP4-6题目集总结

    4-6次题目集,从集合框架,正则表达式,类的继承与多态三个方面展开,在帮助我们了解java常用的工具(集合框架,正则表达式)的同时让我们学着利用类与类之间的关系来减少耦合,第六次题目集侧重于类的继承与 ...

  5. 在linux上启动arthas报“Can not find java process”

    发生背景 完整报错信息: [***@localhost ~]$ java -jar arthas-boot.jar [INFO] JAVA_HOME: /usr/lib/jvm/java-1.8.0- ...

  6. 使用numpy实现bert模型,使用hugging face 或pytorch训练模型,保存参数为numpy格式,然后使用numpy加载模型推理,可在树莓派上运行

    之前分别用numpy实现了mlp,cnn,lstm,这次搞一个大一点的模型bert,纯numpy实现,最重要的是可在树莓派上或其他不能安装pytorch的板子上运行,推理数据 本次模型是随便在hugg ...

  7. Cilium 系列-3-Cilium 的基本组件和重要概念

    系列文章 Cilium 系列文章 前言 安装完了,我们看看 Cilium 有哪些组件和重要概念. Cilium 组件 如上所述,安装 Cilium 时,会安装几个运行组件(有些是可选组件), 它们各是 ...

  8. python安装后pip用不了 cmd命令窗口提示:Did not provide a command

    遇到的问题: 解决方法: 首先,使用where pip找到我的pip的安装目录 其次,配置环境变量 环境变量已经配置,但是仍是使用的时候直接输入pip提示"Did not provide a ...

  9. Anaconda 使用时,conda activate 失败

    今天使用一台电脑上新安装的 anaconda 时,运行 conda activate, 出现如下报错: 错误提示中,说要把 . C:\ProgramData\Anaconda3\etc\profile ...

  10. SQLite入门指南:轻松学习带有实例的完整教程(含示例)

    SQLite官网:https://www.sqlite.org/index.html 源视频教程:https://www.bilibili.com/video/BV1Zz411i78o 菜鸟教程文档: ...