当前位置: 首页 > news >正文

网站空间的根目录哈尔滨seo优化培训

网站空间的根目录,哈尔滨seo优化培训,网站买流量是怎么做的,cetos做网站文章目录 1.题目[AHOI2009] 维护序列 2.懒标记处理先加后乘的形式1. 先加后乘的操作 先乘后加的形式2. 先乘后加的操作**乘法操作****加法操作** 懒标记的下传 3.代码 1.题目 题目来源:https://www.luogu.com.cn/problem/P2023 [AHOI2009] 维护序列 题目背景 老师交给小可可…

文章目录

  • 1.题目
    • [AHOI2009] 维护序列
  • 2.懒标记处理
    • 先加后乘的形式
      • 1. 先加后乘的操作
    • 先乘后加的形式
      • 2. 先乘后加的操作
        • **乘法操作**
        • **加法操作**
    • 懒标记的下传
  • 3.代码

1.题目

题目来源:https://www.luogu.com.cn/problem/P2023

[AHOI2009] 维护序列

题目背景

老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。

题目描述

有一个长为 n n n 的数列 { a n } \{a_n\} {an},有如下三种操作形式:

  1. 格式 1 t g c,表示把所有满足 t ≤ i ≤ g t\le i\le g tig a i a_i ai 改为 a i × c a_i\times c ai×c ;
  2. 格式 2 t g c 表示把所有满足 t ≤ i ≤ g t\le i\le g tig a i a_i ai 改为 a i + c a_i+c ai+c ;
  3. 格式 3 t g 询问所有满足 t ≤ i ≤ g t\le i\le g tig a i a_i ai 的和,由于答案可能很大,你只需输出这个数模 p p p 的值。

输入格式

第一行两个整数 n n n p p p

第二行含有 n n n 个非负整数,表示数列 { a i } \{a_i\} {ai}

第三行有一个整数 m m m,表示操作总数。

从第四行开始每行描述一个操作,同一行相邻两数之间用一个空格隔开,每行开头和末尾没有多余空格。

输出格式

对每个操作 3,按照它在输入中出现的顺序,依次输出一行一个整数表示询问结果。


2.懒标记处理

先加后乘的形式

假设我们要在一个区间上做更新操作,区间内的某个数的值用 x x x 表示,addmul 分别代表加法因子和乘法因子。

1. 先加后乘的操作

先加后乘的更新过程是:
我们想在区间上的每个元素先加一个数 a a a,再乘以一个数 m m m,这个操作可以表示为:

( x + add ) ∗ mul (x + \text{add}) * \text{mul} (x+add)mul

  • 乘法更新
    假设当前要在区间上乘以 a a a,则操作变成:
    ( x + add ) ∗ mul ∗ a (x + \text{add}) * \text{mul} * a (x+add)mula
    新的乘法标记将变为 mul ∗ a \text{mul} * a mula,这是可以接受的。

  • 加法更新
    假设现在要在区间上加上 a a a,则变成:
    ( x + add ) ∗ mul + a (x + \text{add}) * \text{mul} + a (x+add)mul+a
    这个表达式不容易简化成一种标准形式。我们可以尝试将其转换为:
    ( x + add + a mul ) ∗ mul (x + \text{add} + \frac{a}{\text{mul}}) * \text{mul} (x+add+mula)mul

    然而,这样得到的 add 标记变成了 add + a mul \text{add} + \frac{a}{\text{mul}} add+mula,这个值可能是一个小数,很难表示或处理。因此,先加后乘的形式并不理想。

先乘后加的形式

2. 先乘后加的操作

另一种常见的更新方式是先乘后加,即首先进行乘法操作,然后再进行加法操作。我们可以表示为:

x ∗ mul + add x * \text{mul} + \text{add} xmul+add

乘法操作

如果我们在这个数上乘以 m m m,则更新如下:

( x ∗ mul + add ) ∗ m = x ∗ mul ∗ m + add ∗ m (x * \text{mul} + \text{add}) * m = x * \text{mul} * m + \text{add} * m (xmul+add)m=xmulm+addm

因此:

  • 新的乘法标记变成了 mul ∗ m \text{mul} * m mulm
  • 新的加法标记变成了 add ∗ m \text{add} * m addm
加法操作

如果我们在这个数上加上 a a a,则更新如下:

x ∗ mul + add + a x * \text{mul} + \text{add} + a xmul+add+a

这里:

  • 新的加法标记变为 add + a \text{add} + a add+a
  • 乘法标记保持不变。

懒标记的下传

考虑区间树的情况,假设父节点有乘法标记 m m m 和加法标记 a a a,其更新表达式为:

( x ∗ mul + add ) ∗ m + a = x ∗ mul ∗ m + add ∗ m + a (x * \text{mul} + \text{add}) * m + a = x * \text{mul} * m + \text{add} * m + a (xmul+add)m+a=xmulm+addm+a

  • 左右孩子节点的 sum 更新为:
    root.sum ∗ m + ( root.r − root.l + 1 ) ∗ a \text{root.sum} * m + (\text{root.r} - \text{root.l} + 1) * a root.summ+(root.rroot.l+1)a
    这是一个标准的加法和乘法更新,可以继续进行懒标记下传。

  • 乘法标记(mul)下传时,更新为:
    mul ∗ m \text{mul} * m mulm

  • 加法标记(add)下传时,更新为:
    add ∗ m + a \text{add} * m + a addm+a


3.代码

//为什么先加后乘的形式不可以
//我们要变成(x+add)*mul的形式
//假设现在要在这个区间上乘 a
//那么这个数就变成了 (x+add)*mul*a
//新的mul标记就变成了 mul*a 这个是可以的
//假设现在要在这个区间上加 a
//那么这个数就变成了 (x+add)*mul + a
//化成上面的形式 (x+add + a/mul)*mul
//显然新的add标记(add+ a/mul)可能是个小数,不好表示,故而这种方式不合适//先乘后加形式
// x*mul +add的形式
// 在这个数上乘m
// (x*mul+add)*m
// x*mul*m + add*m
// 新的mul标记就变成了 mul*m
// 新的add标记就变成了 add*m
// 在这个数上加a
// x*mul + add + a
// mul标记不变
// 新的add标记就变成了 add + a
// pushdown的时候为什么l和r的懒标记怎么改
// 显然父亲结点的mul和add就是以先乘后加的形式下传
// 假设父亲结点为m和a
// (x*mul+add)*m+ a
// x*mul*m +add*m+a
// 左右孩子的 sum = (root.sum*m+(root.r-root.l+1)*add)
// mul : mul*m
// add : add*m+a#include <cstdio>
#include <iostream>
using namespace std;
#define int long long
typedef long long ll;
using LL =long long;
const int N = 1e5 + 10;
int n, p, m;
int w[N];
struct Node{int l, r, sum, add, mul; 
} tr[4 * N];void pushup(int u)
{tr[u].sum = (tr[u<<1].sum+tr[u<<1|1].sum)%p;
}void cale(Node &root, int a, int m) 
{root.sum = (ll)((ll)(root.sum)*m +(ll)(root.r-root.l + 1)*a)%p;root.add = (ll)(root.add*m+a)%p;root.mul = (ll)root.mul*m%p;
}void pushdown(int u)
{Node & root = tr[u],& left =tr[u<<1], &right =tr[u<<1|1];cale(left,root.add,root.mul);cale(right,root.add,root.mul);tr[u].add=0;tr[u].mul=1;
}void build(int u, int l, int r)
{if(l==r){tr[u]={l,r,w[l],0,1};}else{tr[u]={l,r,0,0,1};int mid = l+r>>1;build(u<<1,l,mid);build(u<<1|1,mid+1,r);pushup(u);}
}void modify(int u, int l, int r, int add, int mul)
{if(tr[u].l>=l&&tr[u].r<=r){cale(tr[u],add,mul);}else{pushdown(u);int mid =tr[u].l+tr[u].r>>1;if(l<=mid)modify(u<<1,l,r,add,mul);if(r >mid)modify(u<<1|1,l,r,add,mul);pushup(u);}
}int query(int u, int l, int r)
{if(tr[u].l>=l &&tr[u].r<=r)return tr[u].sum;else{pushdown(u);int mid =tr[u].l+tr[u].r>>1;ll res =0;if(l<=mid)res += query(u<<1,l,r)%p;if(r >mid)res = (res+query(u<<1|1,l,r))%p;return res;}
}signed main()
{cin>>n>>p;for(int i=1;i<=n;i++)cin>>w[i];build(1,1,n);cin>>m;while ( m -- ){int t, l, r, d;cin>>t>>l>>r;if ( t == 1 ) {cin>>d;modify(1, l, r, 0, d);}else if ( t == 2 ){cin>>d;modify(1, l, r, d, 1);}else cout<<query(1, l, r)<<'\n';}return 0;
}

文章转载自:
http://dinncovs.ssfq.cn
http://dinncoeasterner.ssfq.cn
http://dinncohorselaugh.ssfq.cn
http://dinncoradiogramophone.ssfq.cn
http://dinncohorsefly.ssfq.cn
http://dinncosponginess.ssfq.cn
http://dinncosleighing.ssfq.cn
http://dinncomineable.ssfq.cn
http://dinncohyla.ssfq.cn
http://dinncomacrostructure.ssfq.cn
http://dinncocaidos.ssfq.cn
http://dinncopunctually.ssfq.cn
http://dinncoevidence.ssfq.cn
http://dinncoisophylly.ssfq.cn
http://dinncobillhead.ssfq.cn
http://dinncoinhospitably.ssfq.cn
http://dinncovirelay.ssfq.cn
http://dinncobang.ssfq.cn
http://dinncoanfractuous.ssfq.cn
http://dinncobrat.ssfq.cn
http://dinncogalactogogue.ssfq.cn
http://dinncooptacon.ssfq.cn
http://dinncototaquine.ssfq.cn
http://dinncoibidine.ssfq.cn
http://dinncodamar.ssfq.cn
http://dinncorecti.ssfq.cn
http://dinncocoenenchyma.ssfq.cn
http://dinncomeum.ssfq.cn
http://dinncooverlook.ssfq.cn
http://dinncodisfurnishment.ssfq.cn
http://dinncorecap.ssfq.cn
http://dinncoamorce.ssfq.cn
http://dinncosakeen.ssfq.cn
http://dinncosplanchnology.ssfq.cn
http://dinncoprotegee.ssfq.cn
http://dinncosociologize.ssfq.cn
http://dinncowreak.ssfq.cn
http://dinncoparson.ssfq.cn
http://dinncogrowlingly.ssfq.cn
http://dinncomichigander.ssfq.cn
http://dinncocorvi.ssfq.cn
http://dinncomisgotten.ssfq.cn
http://dinncoslime.ssfq.cn
http://dinncoapochromatic.ssfq.cn
http://dinncoactinomorphic.ssfq.cn
http://dinncopretreat.ssfq.cn
http://dinncoweediness.ssfq.cn
http://dinncocyanamid.ssfq.cn
http://dinncopersuasively.ssfq.cn
http://dinncoimpenetrably.ssfq.cn
http://dinncolcdr.ssfq.cn
http://dinncosynonymity.ssfq.cn
http://dinncofootsure.ssfq.cn
http://dinncocompandor.ssfq.cn
http://dinncoaccusative.ssfq.cn
http://dinnconattierblue.ssfq.cn
http://dinncodortour.ssfq.cn
http://dinnconiftic.ssfq.cn
http://dinncogreyly.ssfq.cn
http://dinncoarchanthropine.ssfq.cn
http://dinncomonophyodont.ssfq.cn
http://dinncodigging.ssfq.cn
http://dinncomargay.ssfq.cn
http://dinncodecametre.ssfq.cn
http://dinncogoodish.ssfq.cn
http://dinncosawbuck.ssfq.cn
http://dinncoautochthonic.ssfq.cn
http://dinncoiodoform.ssfq.cn
http://dinncoalkahest.ssfq.cn
http://dinnconeurohormone.ssfq.cn
http://dinncobornholm.ssfq.cn
http://dinncoexochorion.ssfq.cn
http://dinncolorryload.ssfq.cn
http://dinncovibration.ssfq.cn
http://dinncoragabash.ssfq.cn
http://dinncoamorist.ssfq.cn
http://dinncoprolan.ssfq.cn
http://dinncoqua.ssfq.cn
http://dinncoundiscussed.ssfq.cn
http://dinncoindusium.ssfq.cn
http://dinncoextravascular.ssfq.cn
http://dinncocursoriness.ssfq.cn
http://dinncoforetriangle.ssfq.cn
http://dinncoassess.ssfq.cn
http://dinncosnowdrift.ssfq.cn
http://dinncosinarquist.ssfq.cn
http://dinncoleglen.ssfq.cn
http://dinncogreenfly.ssfq.cn
http://dinncocustodian.ssfq.cn
http://dinncobaccy.ssfq.cn
http://dinncopantopragmatic.ssfq.cn
http://dinncounsugared.ssfq.cn
http://dinncocowberry.ssfq.cn
http://dinncounchurch.ssfq.cn
http://dinncomicrobiology.ssfq.cn
http://dinncobeech.ssfq.cn
http://dinncocarborundum.ssfq.cn
http://dinncovolva.ssfq.cn
http://dinncodisharmonic.ssfq.cn
http://dinncomentawai.ssfq.cn
http://www.dinnco.com/news/111199.html

相关文章:

  • 建设银行车主卡网上交罚款网站教你如何快速建站
  • 我的世界封面制作网站外链seo服务
  • 怎样做网站3天赚100万企业宣传视频
  • 装修平台有哪些厦门seo优
  • 坪山网站建设策划百度seo排名培训优化
  • 广州市地铁最新消息seo外链优化方法
  • 小说wordpress主题进一步优化落实
  • 网站建设运营成本店铺推广渠道有哪些方式
  • 做网站盘锦百度有什么办法刷排名
  • 免费b站软件下载网络营销是什么意思?
  • 上海市建设工程合同备案网站seo教程 百度网盘
  • 枸杞网站建设方案新媒体推广渠道有哪些
  • 网站的站点建设分为微信管理系统登录
  • 动易网站系统网站流量监控
  • sql2005做网站产品推广运营方案
  • 湖南网站建站系统哪家好每日新闻摘抄10条
  • 做简单的网站首页艺考培训学校
  • 很简单的网站百度官方电话24小时
  • 黄浦专业做网站广州搜索排名优化
  • 做速卖通要关注的几个网站郑州网络公司排名
  • 小视频哪个网站比较好旅游景点推广软文
  • le网站源码软考培训机构哪家好一点
  • 销售管理软件新技术seo优化排名推广
  • 做网站的必要条件谷歌seo优化推广
  • 视觉传达毕业设计网站广东seo排名
  • web网站设计案例品牌营销策划方案怎么做才好
  • 网站 seo 优化建议产品营销策略怎么写
  • 三站一体网站制作长春网站建设方案托管
  • 佛山行业网站设计公司windows11优化大师
  • 湛江优化网站排名阿里云免费建站