loj#2552. 「CTSC2018」假面
题目链接
题解
本题严谨的证明了我菜的本质
对于砍人的操作好做找龙哥就好了,blood很少,每次暴力维护一下
对于操作1
设\(a_i\)为第i个人存活的概率,\(d_i\)为死掉的概率,\(g_{i,j}\)是除i以外活了j个人的概率
那个选中i人的答案就是
\]
对于\(g_{i,j}\) ,设\(f_{i,j}\)表示前\(i\)个人有\(j\)个活着的概率,\(f_{i,j}\)可以dp出来
\]
我们可以枚举每次\(g_{i,j}\)的i,然后skip掉,这样的复杂度是\(n^3\)的
然后就可以前缀后缀背包卷积NTT,或者单点删除的分治做法hhhhhhh
其实这个被背包删除物品可以做O(n)
逆着推一下就好了
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c <= '9' && c >= '0') x = x * 10 + c - '0' ,c = getchar();
return x * f;
}
const int mod = 998244353;
const int maxn = 2007;
long long b[maxn];
int n,m ;
long long p[maxn][maxn];
long long inv[maxn];
inline int add(int x,int y) {
return x + y >= mod ? x + y - mod : x + y;
}
inline int fstpow(int x,int k) {
int ret = 1;
for(;k;k >>= 1,x = 1ll *x * x % mod)
if(k & 1) ret = 1ll * ret * x % mod;
return ret;
}
void solve1(int x,int P) {
int rp = 1 + mod - P;
for(int i = 0;i <= b[x];++ i) {
if(i) p[x][i] = 1ll * p[x][i] * rp % mod;
if(i < b[x]) p[x][i] = add(p[x][i] , 1ll * p[x][i + 1] * P % mod) ;
}
}
int k;
void solve(int k) {
static long long f[maxn],g[maxn],h[maxn],t[maxn];
// f存活j个人的概率
memset(f,0,sizeof f);
f[0] = 1;
for(int i = 1;i <= k;++ i) t[i] = read();
for(int a,d,i = 1;i <= k;++ i) {
a = 1 + mod - p[t[i]][0];
d = p[t[i]][0];
for(int j = i;j >= 0;-- j)
f[j] = add((j ? 1ll * f[j - 1] * a % mod : 0) , 1ll * f[j] * d % mod);
}
for(int i = 1;i <= k;++ i) {
h[i] = 0;
int a = 1 + mod - p[t[i]][0];
if(!p[t[i]][0])
for(int j = 0;j < k;++ j) h[i] = add(h[i],1ll * f[j + 1] * inv[j + 1] % mod);
else {
int Inv = fstpow(p[t[i]][0],mod - 2);
for(int j = 0;j < k;++ j) {
g[j] = ((f[j] - (j ? 1ll * g[j - 1] * a % mod : 0) + mod) % mod) * Inv % mod;
h[i] = add(h[i],1ll * g[j] * inv[j + 1] % mod);
}
}
h[i] = 1ll * h[i] * a % mod;
}
for(int i = 1;i <= k;++ i) printf("%d ",h[i]);
puts("");
}
main() {
//freopen("facel5.in","r",stdin); freopen("w.out","w",stdout);
n = read();
for(int i = 1;i <= n;++ i) b[i] = read(), p[i][b[i]] = 1,inv[i] = fstpow(i,mod - 2);
m = read();
for(int op,i = 1;i <= m;i += 1) {
op = read();
if(!op) {
int x = read(),u = read(),v = read();
solve1(x,1ll * u * fstpow(v,mod - 2) % mod);
}
else
solve(read());
}
for(int i = 1;i <= n;++ i) {
int sum = 0;
for(int j = 1;j <= b[i];++ j)
sum = add(sum , 1ll * j * p[i][j] % mod) ;
printf("%d%c",sum,i != n ? ' ' : '\n');
}
return 0;
}
loj#2552. 「CTSC2018」假面的更多相关文章
- LOJ 2552 「CTSC2018」假面——DP
题目:https://loj.ac/problem/2552 70 分就是 f[i][j] 表示第 i 个人血量为 j 的概率.这部分是 O( n*Q ) 的:g[i][j][0/1] 表示询问的人中 ...
- LOJ#2552. 「CTSC2018」假面(期望 背包)
题意 题目链接 Sol 多年以后,我终于把这题的暴力打出来了qwq 好感动啊.. 刚开始的时候想的是: 设\(f[i][j]\)表示第\(i\)轮, 第\(j\)个人血量的期望值 转移的时候若要淦这个 ...
- Loj #2554. 「CTSC2018」青蕈领主
Loj #2554. 「CTSC2018」青蕈领主 题目描述 "也许,我的生命也已经如同风中残烛了吧."小绿如是说. 小绿同学因为微积分这门课,对"连续"这一概 ...
- Loj #2553. 「CTSC2018」暴力写挂
Loj #2553. 「CTSC2018」暴力写挂 题目描述 temporaryDO 是一个很菜的 OIer .在 4 月,他在省队选拔赛的考场上见到了<林克卡特树>一题,其中 \(k = ...
- LOJ 2553 「CTSC2018」暴力写挂——边分治+虚树
题目:https://loj.ac/problem/2553 第一棵树上的贡献就是链并,转化成 ( dep[ x ] + dep[ y ] + dis( x, y ) ) / 2 ,就可以在第一棵树上 ...
- LOJ 2557 「CTSC2018」组合数问题 (46分)
题目:https://loj.ac/problem/2557 第一个点可以暴搜. 第三个点无依赖关系,k=3,可以 DP .dp[ cr ][ i ][ j ] 表示前 cr 个任务.第一台机器最晚完 ...
- LOJ 2555 「CTSC2018」混合果汁——主席树
题目:https://loj.ac/problem/2555 二分答案,在可以选的果汁中,从价格最小的开始选. 按价格排序,每次可以选的就是一个前缀.对序列建主席树,以价格为角标,维护体积和.体积*价 ...
- LOJ 2554 「CTSC2018」青蕈领主——结论(思路)+分治FFT
题目:https://loj.ac/problem/2554 一个“连续”的区间必然是一个排列.所有 r 不同的.len 最长的“连续”区间只有包含.相离,不会相交,不然整个是一个“连续”区间. 只有 ...
- LOJ #2533. 「CTSC2018」暴力写挂(边分治合并)
题意 给你两个有 \(n\) 个点的树 \(T, T'\) ,求一对点对 \((x, y)\) 使得 \[ depth(x) + depth(y) - (depth(LCA(x , y)) + dep ...
随机推荐
- ubuntu 系统关键指令
1. 查看系统版本号 cat /etc/issue uname -a cat /proc/version 2. linux 32/64 bit? getconf LONG_BIT 3. dpkg 的命 ...
- SpringBoot使用其他的Servlet容器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- 如何提交内核补丁--checkpatch.pl使用【转】
转自:https://blog.csdn.net/qq_29350001/article/details/52056667 转自: http://blog.csdn.net/ganggexiongqi ...
- 在全志平台调试博通的wifi驱动(类似ap6212)【转】
转自:http://blog.csdn.net/fenzhi1988/article/details/44809779 调试驱动之前,首先先看看驱动代码,了解代码大致工作流程,再根据硬件配置驱动,比如 ...
- linux 内核分析工具 Dtrace、SystemTap、火焰图、crash等
<< System语言详解 >> 关于 SystemTap 的书. 我们在分析各种系统异常和故障的时候,通常会用到 pstack(jstack) /pldd/ lsof/ tc ...
- Ubuntu/Debian apt-get 404 Not Found Package Repository Errors,无法找到包的错误
最简单最常用的方法是,使用如下命令更新到新的版本: sudo apt-get dist-upgrade 但是这个方法有时候不一定能起作用,那么可以使用以下直接替换的命令: sudo sed -i -e ...
- nodejs 数据库操作,消息的发送和接收,模拟同步
var deasync = require('deasync'); //导入模板 var mysql=require('mysql'); var Stomp = require('stompjs'); ...
- mysql安装与卸载(绿色版)
1.下载压缩包,解压 2.配置环境变量 PATH:%MYSQL_HOME%\bin 3.在安装目录下新建my.ini配置文件: [mysql] default-character-set=utf8 [ ...
- Shell 中test 单中括号[] 双中括号[[]] 的区别
Shell test 单中括号[] 双中括号[[]] 的区别 在写Shell脚本的时候,经常在写条件判断语句时不知道该用[] 还是 [[]],首先我们来看他们的类别: $type [ [[ test ...
- haproxy配置基于ssl证书的https负载均衡
本实验全部在haproxy1.5.19版本进行测试通过,经过测试1.7.X及haproxy1.3版本以下haproxy配置参数可能不适用,需要注意版本号. 一.业务要求现在根据业务的实际需要,有以下几 ...