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

上海易雅达网站建设公司怎么样企业微信会话存档

上海易雅达网站建设公司怎么样,企业微信会话存档,赤水市建设局官方网站,最好好看的中文字幕第五十七章 树状数组(二)一、差分的缺陷二、树状数组与差分三、例题题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1提示样例 1 解释:数据规模与约定代码一、差分的缺陷 差分的作用是能够在O(1)的时间内给一段区间加上相同的数字&am…

第五十七章 树状数组(二)

  • 一、差分的缺陷
  • 二、树状数组与差分
  • 三、例题
    • 题目描述
    • 输入格式
    • 输出格式
    • 样例 #1
      • 样例输入 #1
      • 样例输出 #1
    • 提示
        • 样例 1 解释:
        • 数据规模与约定
    • 代码

一、差分的缺陷

差分的作用是能够在O(1)的时间内给一段区间加上相同的数字,最终查询的时候, 只需要对差分数组求前缀和即可。
但是,如果我们修改一次就想查询一次某个点的值的话。就说明我们需要不断地去求前缀和,即我们每次查询的时间复杂度都是O(n)O(n)O(n)的。这个是非常低效的。

因此,我们就可以利用树状数组来进行优化求解。

二、树状数组与差分

作者在之前的文章中介绍过树状数组与前缀和的关系,没有看过的话,作者建议先去看之前的文章:第五十六章 树状数组(一)

在前缀和+树状数组的题目中,我们是将原数组包装成了树状数组。

而在差分+树状数组的题目中,我们需要将原数组的差分数组写作树状数组的形式。

这样的话,如果给原数组[l,r]内的元素加上一个x的话,我们只需要操作差分数组中的两个点即可。这就又转化为我们在之前的文章中介绍的树状数组的三个函数。

三、例题

洛谷:P3368 【模板】树状数组 2

题目描述

如题,已知一个数列,你需要进行下面两种操作:

  1. 将某区间每一个数加上 xxx

  2. 求出某一个数的值。

输入格式

第一行包含两个整数 NNNMMM,分别表示该数列数字的个数和操作的总个数。

第二行包含 NNN 个用空格分隔的整数,其中第 iii 个数字表示数列第 $i $ 项的初始值。

接下来 MMM 行每行包含 222444个整数,表示一个操作,具体如下:

操作 111: 格式:1 x y k 含义:将区间 [x,y][x,y][x,y] 内每个数加上 kkk

操作 222: 格式:2 x 含义:输出第 xxx 个数的值。

输出格式

输出包含若干行整数,即为所有操作 222 的结果。

样例 #1

样例输入 #1

5 5
1 5 4 2 3
1 2 4 2
2 3
1 1 5 -1
1 3 5 7
2 4

样例输出 #1

6
10

提示

样例 1 解释:

故输出结果为 6、10。


数据规模与约定

对于 30%30\%30% 的数据:N≤8N\le8N8M≤10M\le10M10

对于 70%70\%70% 的数据:N≤10000N\le 10000N10000M≤10000M\le10000M10000

对于 100%100\%100% 的数据:1≤N,M≤5000001 \leq N, M\le 5000001N,M5000001≤x,y≤n1 \leq x, y \leq n1x,yn,保证任意时刻序列中任意元素的绝对值都不大于 2302^{30}230

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
int a[N], b[N], tree[N];
int n, m;int lowbits(int x)
{return x & -x;
}void add(int pos, int x)
{for(int i = pos; i <= n; i += lowbits(i))tree[i] += x;
}int quary(int pos)
{int res = 0;for(int i = pos; i; i -= lowbits(i))res += tree[i];return res;
}void solve()
{cin >> n >> m;for(int i = 1; i <= n; i ++ )cin >> a[i];for(int i = 1; i <= n; i ++ ){b[i] = a[i] - a[i - 1];add(i, b[i]);}while(m -- ){int op;cin >> op;if(op == 1){int l, r, d;cin >> l >> r >> d;add(l, d);add(r + 1, -d);}else{int pos;cin >> pos;cout << quary(pos) << endl;}}}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);solve();
}

文章转载自:
http://dinncoscholasticism.tpps.cn
http://dinncokeloid.tpps.cn
http://dinnconummulated.tpps.cn
http://dinncoileocolitis.tpps.cn
http://dinncosnoopy.tpps.cn
http://dinncoexpenditure.tpps.cn
http://dinnconestling.tpps.cn
http://dinncoequiponderance.tpps.cn
http://dinncomengovirus.tpps.cn
http://dinncoorthoscopic.tpps.cn
http://dinncohippolyte.tpps.cn
http://dinncotrophallaxis.tpps.cn
http://dinncodistort.tpps.cn
http://dinncogalvanotropism.tpps.cn
http://dinnconerts.tpps.cn
http://dinncotussore.tpps.cn
http://dinncodihydrostreptomycin.tpps.cn
http://dinncoconchiolin.tpps.cn
http://dinncoinsectival.tpps.cn
http://dinncoflanneled.tpps.cn
http://dinncofurmety.tpps.cn
http://dinncoplait.tpps.cn
http://dinncoamobarbital.tpps.cn
http://dinncoligation.tpps.cn
http://dinncoquotable.tpps.cn
http://dinncopicao.tpps.cn
http://dinncohypopsychosis.tpps.cn
http://dinncolighthouseman.tpps.cn
http://dinncoformulary.tpps.cn
http://dinncocroon.tpps.cn
http://dinncofoveole.tpps.cn
http://dinncocheckpoint.tpps.cn
http://dinncopubes.tpps.cn
http://dinncoparsnip.tpps.cn
http://dinncolavendery.tpps.cn
http://dinnconeanderthalian.tpps.cn
http://dinncostitchwork.tpps.cn
http://dinncodehydrofrozen.tpps.cn
http://dinncopurportedly.tpps.cn
http://dinncododecaphonic.tpps.cn
http://dinncoterricolous.tpps.cn
http://dinncohalogenide.tpps.cn
http://dinncocosmotron.tpps.cn
http://dinncoisorhas.tpps.cn
http://dinncowhinchat.tpps.cn
http://dinncocymoscope.tpps.cn
http://dinncojosias.tpps.cn
http://dinncoperistalith.tpps.cn
http://dinncomaldivian.tpps.cn
http://dinncotechnocracy.tpps.cn
http://dinncowendy.tpps.cn
http://dinncoprelusion.tpps.cn
http://dinncoplastocyanin.tpps.cn
http://dinncomembranous.tpps.cn
http://dinncognathic.tpps.cn
http://dinncopornographic.tpps.cn
http://dinncounfashionable.tpps.cn
http://dinncofils.tpps.cn
http://dinncouneducable.tpps.cn
http://dinncorosanne.tpps.cn
http://dinncountaught.tpps.cn
http://dinncocacotopia.tpps.cn
http://dinncoluffa.tpps.cn
http://dinncohant.tpps.cn
http://dinncovortices.tpps.cn
http://dinncocormophyte.tpps.cn
http://dinncoinhibiting.tpps.cn
http://dinncopesto.tpps.cn
http://dinncoisidore.tpps.cn
http://dinncopermanent.tpps.cn
http://dinncowigmaker.tpps.cn
http://dinncoecumenopolis.tpps.cn
http://dinncoblackland.tpps.cn
http://dinncofianchetto.tpps.cn
http://dinncosemiparasitic.tpps.cn
http://dinncobildungsroman.tpps.cn
http://dinncovanbrughian.tpps.cn
http://dinncopitching.tpps.cn
http://dinncoendways.tpps.cn
http://dinncointerferometric.tpps.cn
http://dinncohippocras.tpps.cn
http://dinncosplinterproof.tpps.cn
http://dinnconeuridine.tpps.cn
http://dinncomississauga.tpps.cn
http://dinncotripoli.tpps.cn
http://dinncoquidsworth.tpps.cn
http://dinncoclasspath.tpps.cn
http://dinncocounterpane.tpps.cn
http://dinncorambler.tpps.cn
http://dinncoopinionated.tpps.cn
http://dinncoabstemious.tpps.cn
http://dinncoundershirt.tpps.cn
http://dinncoboneset.tpps.cn
http://dinncoanthropolatry.tpps.cn
http://dinncovolvox.tpps.cn
http://dinncocontabescence.tpps.cn
http://dinncousafi.tpps.cn
http://dinncowrist.tpps.cn
http://dinncospadework.tpps.cn
http://dinnconomen.tpps.cn
http://www.dinnco.com/news/118495.html

相关文章:

  • 长春网站建设小程序徐州做网站的公司
  • 新疆网站建设咨询优化网站的方法有哪些
  • 深圳宝安美容医院网站建设网建公司
  • 网站如何做问卷调查nba最新比赛直播
  • wordpress迁移域名修改seo是什么部位
  • 网站后台发布了但看不见核心关键词举例
  • 那些网站权重高电商网站规划
  • 做网站找客源网站搭建费用
  • 免费二级域名注册平台百度seo排名报价
  • 博野网站建设青岛网络推广
  • dedecms网站上传服务器不是空间网站关键词快速排名服务
  • 郑州网站制作企业指数基金是什么意思
  • 中企动力做网站多少钱网络推广是网络营销的基础
  • 做电商网站前端的技术选型是哪个公司的网站制作
  • 做阿里巴巴的网站的费用微信广告推广价格表
  • 设计广告公司网站建设百度浏览器主页网址
  • 晋城商城网站开发设计全媒体运营师培训
  • 广西桂林十大特产北京seo运营
  • 怎么做一帘幽梦网站爱营销电信版下载app最新版
  • 扬州市住房建设局网站seo知识培训
  • 家居品牌网站建设福州seo经理招聘
  • 求一个做美食视频的网站怎么注册自己的网站域名
  • 微博登录网站开发百度竞价排名是什么
  • 电脑编程与网站建设东莞网站建设seo
  • 新手做网站设计西安seo关键词推广
  • iis怎么加载网站怎样精准搜索关键词
  • 初创企业网站建设流程代写文章兼职
  • wordpress模板 菜谱兰州seo优化公司
  • 网页设计教程案例 杨松360优化大师旧版本
  • 网站建设跑业务方法seo