传送门

差了一点没想到正解……

首先单次询问的 \(O(n)\) 写法很好想,考虑如何优化

首先基础分区间求和即可

然后那个连击分的话,是一个关于 \(f_i\) 和 \(f_{i-1}\) 的柿子

\[f_i = p*(f_{i-1}+1)+(1-p)*f_{i-1}*t
\]

移个项

\[f_i = (p+t-p*t)f_{i-1}+p
\]

就表示成了一个 \(f_i = k_i*f_{i-1}+b_i\) 的形式

  • 形似 \(f_i = k_i*f_{i-1}+b_i\) 的柿子可以用线段树维护,核心在于维护出每个区间 \(R\) 位置相对 \(L-1\) 位置的 \(k\) 和 \(b\)

于是发现我们要求的 \(\sum p_i(f_{i-1}+1)\) 本来就是一个 \(kx+b\) 的形式

直接维护就好了

Code:
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 500010
#define ll long long
#define reg register int
//#define int long long char buf[1<<21], *p1=buf, *p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1<<21, stdin)), p1==p2?EOF:*p1++)
inline int read() {
int ans=0, f=1; char c=getchar();
while (!isdigit(c)) {if (c=='-') f=-f; c=getchar();}
while (isdigit(c)) {ans=(ans<<3)+(ans<<1)+(c^48); c=getchar();}
return ans*f;
} int n, q, sub;
int ta, tb, A, B, t, pa, pb;
int p[N], c[N];
const ll mod=998244353;
const int mod2=998244353;
inline void md(int& a, ll b) {a+=b; a=a>=mod2?a-mod2:a;}
inline int md(int a) {return a>=mod2?a-mod2:a;}
struct equ{int k, b, sumk, sumb; equ(){} equ(int e, int f, int g, int h):k(e),b(f),sumk(g),sumb(h){}};
inline equ operator + (equ a, equ b) {
equ ans;
ans.k=1ll*a.k*b.k%mod;
ans.b=(1ll*b.k*a.b+b.b)%mod;
ans.sumk=(a.sumk+1ll*b.sumk*a.k)%mod;
ans.sumb=(a.sumb+1ll*b.sumk*a.b+b.sumb)%mod;
return ans;
}
int tl[N<<2], tr[N<<2], sum[N<<2]; equ sk[N<<2];
#define tl(p) tl[p]
#define tr(p) tr[p]
#define sum(p) sum[p]
#define sk(p) sk[p]
#define k(p) sk[p].k
#define b(p) sk[p].b
#define sumk(p) sk[p].sumk
#define sumb(p) sk[p].sumb
inline void pushup(int p) {
sum(p)=md(sum(p<<1)+sum(p<<1|1));
sk(p)=sk(p<<1)+sk(p<<1|1);
}
void build(int tp, int l, int r) {
tl(tp)=l; tr(tp)=r;
if (l==r) {sum(tp)=p[l]; k(tp)=(p[l]+t-1ll*p[l]*t)%mod; b(tp)=sumk(tp)=sumb(tp)=p[l]; return ;}
int mid=(tl(tp)+tr(tp))>>1;
build(tp<<1, l, mid);
build(tp<<1|1, mid+1, r);
pushup(tp);
}
void upd(int p, int pos, int dat) {
if (tl(p)==tr(p)) {sum(p)=dat; k(p)=(dat+t-1ll*dat*t)%mod; b(p)=sumk(p)=sumb(p)=dat; return ;}
int mid=(tl(p)+tr(p))>>1;
if (pos<=mid) upd(p<<1, pos, dat);
else upd(p<<1|1, pos, dat);
pushup(p);
}
int queryA(int p, int l, int r) {
if (l<=tl(p) && r>=tr(p)) return sum(p);
int mid=(tl(p)+tr(p))>>1, ans=0;
if (l<=mid) md(ans, queryA(p<<1, l, r));
if (r>mid) md(ans, queryA(p<<1|1, l, r));
return ans;
}
equ query(int p, int l, int r) {
if (l<=tl(p) && r>=tr(p)) return sk(p);
int mid=(tl(p)+tr(p))>>1;
if (l<=mid && r>mid) return query(p<<1, l, r)+query(p<<1|1, l, r);
if (l<=mid) return query(p<<1, l, r);
if (r>mid) return query(p<<1|1, l, r);
puts("error");
return sk(p);
}
int queryA(int l, int r) {
int tem=1ll*A*queryA(1, l, r)%mod;
return md(tem+mod);
} ll qpow(ll a, ll b) {
ll ans=1;
while (b) {
if (b&1) ans=ans*a%mod;
a=a*a%mod; b>>=1;
}
return ans;
} #if 0
namespace force{
ll query(int l, int r) {
ll base=0, com=0;
for (int i=l; i<=r; ++i) md(base, p[i]);
base=base*A%mod;
c[l]=p[l]; md(com, p[l]%mod);
for (int i=l+1; i<=r; ++i) {
c[i]=(p[i]*(c[i-1]+1)%mod + (1-p[i])*c[i-1]%mod*t%mod)%mod;
c[i]=(c[i]%mod+mod)%mod;
md(com, p[i]*(c[i-1]+1)%mod);
}
ll tem=(base+com*B%mod)%mod;
//assert(tem>=0);
return (tem+mod)%mod;
}
void solve() {
for (int i=1,op,l,r,x; i<=q; ++i) {
op=read();
if (op&1) {
l=read(); r=read();
printf("%lld\n", query(l, r));
}
else {
x=read(); pa=read(); pb=read();
p[x]=pa*qpow(pb, mod-2)%mod;
}
}
exit(0);
}
} namespace task1{
void solve() {
build(1, 1, n);
for (int i=1; i<=n; ++i) upd(1, i, p[i]);
for (int i=1,op,l,r,x; i<=q; ++i) {
op=read();
if (op&1) {
l=read(); r=read();
printf("%lld\n", queryA(l, r));
}
else {
x=read(); pa=read(); pb=read();
p[x]=pa*qpow(pb, mod-2)%mod;
upd(1, x, p[x]);
}
}
exit(0);
}
}
#endif namespace task{
void solve() {
build(1, 1, n);
equ tem;
for (reg i=1,op,l,r,x; i<=q; ++i) {
op=read();
if (op&1) {
l=read(); r=read();
//cout<<"op=1"<<endl;
if (l==r) printf("%lld\n", (p[l]*A+p[l]*B)%mod);
else {
tem=query(1, l+1, r);
ll ans=(1ll*p[l]*tem.sumk+tem.sumb+p[l])%mod*B+queryA(l, r);
ans = md(ans%mod+mod);
printf("%lld\n", ans);
}
}
else {
x=read(); pa=read(); pb=read();
p[x]=pa*qpow(pb, mod-2)%mod;
upd(1, x, p[x]);
}
}
exit(0);
}
} signed main()
{
sub=read();
n=read(); q=read(); ta=read(); tb=read(); A=read(); B=read();
if (!q) return 0;
t=ta*qpow(tb, mod-2)%mod;
for (reg i=1; i<=n; ++i) {
pa=read(); pb=read();
p[i]=pa*qpow(pb, mod-2)%mod;
}
//if (!B) task1::solve();
//else force::solve();
task::solve(); return 0;
}

题解 Omeed的更多相关文章

  1. 20210824 Prime,Sequence,Omeed

    考场 T1 貌似是 luogu 上原题 T2 计数,想起了这题和这题,但没有 \(n^2\) 一档的分...准备打个表 T3 期望 DP,但暴力是 \(O(qn)\) 的,发现 \(combo\) 的 ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. 74cms v5.0.1 前台sql注⼊复现

    漏洞简介 74cms 5.0.1 前台AjaxPersonalController.class.php存在SQL注⼊ 复现过程 具体信息 文件位置 74cms\upload\Application\H ...

  2. Selenium执行完毕未关闭chromedriver/geckodriver进程的解决办法(java版+python版)

    selenium操作chrome浏览器需要有ChromeDriver驱动来协助.webdriver中关浏览器关闭有两个方法,一个叫quit,一个叫close. 1 /** 2 * Close the ...

  3. c语言:结果不理解

    #include <stdio.h> int main() { int a;float b; scanf("a=%d,b=%f",&a,&b); pri ...

  4. python3安装pp过程

    并行计算的目的是将所有的核心都运行起来以提高代码的执行速度,在python中由于存在全局解释器锁(GIL)如果使用默认的python多线程进行并行计算可能会发现代码的执行速度并不会加快,甚至会比使用但 ...

  5. Python基础之魔术方法(控制属性的访问和设置)

    # 魔术方法--常规方法# 1. __int__ 构造函数# 2. __new__ 在类实例之前就创建了# 3. __iter__ 迭代器# 4. __del__ 析构方法,用来清除释放的对象内存# ...

  6. 微信小程序云开发-云函数-数据库和云函数获取数据的区别

    一.数据库获取数据 1.1 数据库获取数据的写法 在本地创建的页面js文件中写代码 1.2 数据库获取数据返回数据限制20条 数据库获取数据,每次返回20条数据(数据库有108条数据) 1.3 数据库 ...

  7. hash表/哈希表

    https://blog.csdn.net/duan19920101/article/details/51579136 简单理解就是一个通过映射直接查找的表(散列表),用哈希函数将数据按照其存储特点进 ...

  8. js循环修改对象内层元素的值

    问题:存在一个对象,该对象的内部元素也为对象,子对象的元素也为对象,...(即多层对象构成的对象,具体如下),那么应该如何修改最内层元素的值(如 obj.a.a.a = 5)? var obj = { ...

  9. odoo14里面给下载PDF附件加水印

    依赖包:pip install reportlab Odoo 中附件的下载会经过 ir.http 的 def binary_content() 方法获取附件内容等必要信息, 所以我们需要继承 ir.h ...

  10. python算法学习--待续

    几个算法网站 算法可视化网站:https://visualgo.net/en,通过动画展示算法实现过程 程序可视化网站:http://www.pythontutor.com/visualize.htm ...