Zbq's Music Challenge

题意

  一个长度为n的序列,每个位置可能是1或者0,1的概率是$p_i$。对于一个序列$S$,它的得分是

$$BasicScore=A\times \sum_{i=1}^{n}{S_i} \tag{1}$$

$$ combo(i)=\left\{ \begin{aligned} &S_i & &i=1 \\ &combo(i-1)+1 & &i\neq 1 ~\mathrm{and}~ S_i=1 \\ &combo(i-1)\times t & &\mathrm{otherwise} \end{aligned} \tag{2} \right.$$

$$ComboScore=B\times \sum_{i=1}^{n}{S_i\times combo(i)} \tag{3}$$

$$TotalScore=BasicScore+ComboScore \tag{4}$$

  两种操作,修改每个位置的概率,询问一段区间得分的期望,答案对$998244353$取模。

分析

  分成两部分算,$BasicScore$可以对$p_i$求和得到。

  对于每段区间,$f[i]$设第i位置数字期望是多少,那么$ComboScore = B \times \sum\limits_{i=l}^{r} p_i \times (f[i-1] + 1) $。

  然后转移可以写成矩阵的形式。

  $$ \left[ \begin{matrix} 1 & p_i & p_i \\ 0 & (1 - p_i) \times t + p_i & p_i\\ 0 & 0 & 1 \end{matrix} \right] \times \left[ \begin{matrix} sum\\ f[i - 1]\\ 1 \end{matrix} \right] = \left[ \begin{matrix} sum' \\ f[i]\\ 1 \end{matrix} \right] $$

  于是,线段树维护一下即可。复杂度$O(nlogn \times 3^3)$

代码

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cctype>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int mod = ;
const int N = ;
int p[N]; int ksm(int a,int b) {
int res = ;
while (b) {
if (b & ) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= ;
}
return res;
}
int fen(int a,int b) { return 1ll * a * ksm(b, mod - ) % mod; } int sum[N << ], tt, NowAns, n, A, B;
struct Mat{
int a[][];
Mat() { memset(a, , sizeof(a)); }
void set(int p) {
a[][] = ;
a[][] = a[][] = a[][] = p;
a[][] = (1ll * (mod + - p) % mod * tt % mod + p) % mod;
a[][] = ;
}
}T[N << ];
Mat operator * (const Mat &A, const Mat &B) {
Mat C;
for (int k = ; k < ; ++k)
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
C.a[i][j] = (C.a[i][j] + 1ll * A.a[i][k] * B.a[k][j] % mod) % mod;
return C;
}
inline void pushup(int rt) {
T[rt] = T[rt << ] * T[rt << | ];
sum[rt] = (sum[rt << ] + sum[rt << | ]) % mod;
}
void build(int l,int r,int rt) {
if (l == r) {
T[rt].set(p[l]); sum[rt] = p[l]; return ;
}
int mid = (l + r) >> ;
build(l, mid, rt << ); build(mid + , r, rt << | );
pushup(rt);
}
void update(int l,int r,int rt,int pos) {
if (l == r) {
T[rt].set(p[l]); sum[rt] = p[l]; return ;
}
int mid = (l + r) >> ;
if (pos <= mid) update(l, mid, rt << , pos);
else update(mid + , r, rt << | , pos);
pushup(rt);
}
Mat query(int l,int r,int rt,int L,int R) {
if (L <= l && r <= R) { NowAns = (NowAns + sum[rt]) % mod; return T[rt]; }
int mid = (l + r) >> ;
if (R <= mid) return query(l, mid, rt << , L, R);
else if (L > mid) return query(mid + , r, rt << | , L, R);
else return query(l, mid, rt << , L, R) * query(mid + , r, rt << | , L, R);
}
void query() {
int x = read(), y = read();
NowAns = ;
Mat now = query(, n, , x, y);
LL ans1 = NowAns, ans2 = now.a[][];
cout << (1ll * ans1 * A % mod + 1ll * ans2 * B % mod) % mod << "\n";
}
int main() {
read();
n = read();int Q = read(), ta = read(), tb = read();A = read(), B = read();
tt = fen(ta, tb);
for (int i = ; i <= n; ++i)
ta = read(), tb = read(), p[i] = fen(ta, tb);
build(, n, );
while (Q --) {
if (read()) query();
else {
int x = read(), ta = read(), tb = read();
p[x] = fen(ta, tb);
update(, n, , x);
}
}
return ;
}

校内模拟赛 Zbq's Music Challenge的更多相关文章

  1. 【20170521校内模拟赛】热爱生活的小Z

    学长FallDream所出的模拟赛,个人感觉题目难度还是比较适中的,难度在提高+左右,可能比较接近弱省省选,总体来讲试题考查范围较广,个人认为还是很不错的. 所有试题如无特殊声明,开启-O2优化,时限 ...

  2. Java实现蓝桥杯第十一届校内模拟赛

    有不对的地方欢迎大佬们进行评论(ง •_•)ง 多交流才能进步,互相学习,互相进步 蓝桥杯交流群:99979568 欢迎加入 o( ̄▽ ̄)ブ 有一道题我没写,感觉没有必要写上去就是给你多少MB然后求计 ...

  3. 【20170920校内模拟赛】小Z爱学习

    所有题目开启-O2优化,开大栈空间,评测机效率为4亿左右. T1 小 Z 学数学(math) Description ​ 要说小 Z 最不擅长的学科,那一定就是数学了.这不,他最近正在学习加法运算.老 ...

  4. 校内模拟赛 Attack's Fond Of LeTri

    Attack's Fond Of LeTri 题意: n个房子m条路径边的无向图,每个房子可以最终容纳b个人,初始有a个人,中途超过可以超过b个人,每条边有一个长度,经过一条边的时间花费为边的长度.求 ...

  5. 校内模拟赛 SovietPower Play With Amstar

    SovietPower Play With Amstar 题意: 一棵二叉树,每次询问一条路径上的路径和,初始每个点有一个权值1,询问后权值变为0.$n \leq 10^7,m\leq10^6$ 分析 ...

  6. 校内模拟赛 虫洞(by NiroBC)

    题意: n个点m条边的有向图,每一天每条边存在的概率都是p,在最优策略下,询问从1到n的期望天数. 分析: dijkstra. 每次一定会优先选dp最小的后继走,如果这条边不存在,选次小的,以此类推. ...

  7. 校内模拟赛 旅行(by NiroBC)

    题意: n个点的无向图,Q次操作,每次操作可以连接增加一条边,询问两个点之间有多少条边是必经之路.如果不连通,输出-1. 分析: 首先并查集维护连通性,每次加入一条边后,如果这条边将会连接两个联通块, ...

  8. 校内模拟赛 coin

    题意: n*m的棋盘,每个格子可能是反着的硬币,正着的硬币,没有硬币,每次可以选未选择的一行或者未选择的一列,将这一行/列的硬币取反.如果没有可选的或者硬币已经全部正面,那么游戏结束. 最后一次操作的 ...

  9. 校内模拟赛 Label

    题意: n个点m条边的无向图,有些点有权值,有些没有.边权都为正.给剩下的点标上数字,使得$\sum\limits_{(u,v)\in E}len(u,v) \times (w[u] - w[v]) ...

随机推荐

  1. 【Java入门提高篇】Day32 Java容器类详解(十四)ArrayDeque详解

    今天来介绍一个不太常见也不太常用的类——ArrayDeque,这是一个很不错的容器类,如果对它还不了解的话,那么就好好看看这篇文章吧. 看完本篇,你将会了解到: 1.ArrayDeque是什么? 2. ...

  2. Linux笔记(二): WIN 10 Ubuntu 双系统

    (一)  说明 记录一次ubuntu安装过程及遇到的问题. 环境:WIN 10 单硬盘 (二)  ubuntu ISO文件下载 ubuntu 18.04 https://www.ubuntu.com/ ...

  3. VMware-workstation12.5.6 新建虚拟机 安装 centos6.5

    1.到官方下载镜像文件 注意:看到上面那两个红框不要着急复制链接用迅雷下载,因为点击进去是个页面,不知道官方做这个用意是怎样的,个人感觉很傻缺我们只要点击第一个红框就行 *************** ...

  4. Python使用map,reduce高阶函数模拟实现Spark的reduceByKey算子功能

    # 使用默认的高阶函数map和reduce import randomdef map_function(arg):  # 生成测试数据 return (arg,1) list_map = list(m ...

  5. tkinter中lable标签控件(二)

    lable控件 对于tkinter来说,学起来很简单,只要设置好相应的参数即可出结果,所以不用刻意去记住这些参数.学习一遍后理解每个参数的作用是什么即可. 当下次用到的时候来笔记上看一下就行. 内容很 ...

  6. win10下解压版mysql-8.0.12安装教程

    内容转载于:https://blog.csdn.net/hust_hqq/article/details/80572133 在他之上添加了一个:服务名无效的解决方法 1.官网下载安装包 网址:http ...

  7. jquery判断checkBox的checked

    jquery判断checked的三种方法:.attr('checked):   //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false.prop('c ...

  8. 数据库_存储过程简介(oracle版)

    应朋友要求,写个存储过程说明,本篇比较简单,适合新接触存储过程的同学 先来个简单的 begin dbms_output.put_line('my first execute'); end; 如果使用的 ...

  9. SQL SERVER孤立帐号的处理

    Step1:查询 Use KSHR_F23 Go exec sp_change_users_login @Action='Report' Go Step2:处理 Use KSHR_F23 Go exe ...

  10. python redirect和render的区别

    render是渲染变量到模板中,而redirect是HTTP中1个跳转的函数,一般会生成302状态码.