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

如何用模版做网站大连百度seo

如何用模版做网站,大连百度seo,用什么软件做网站,51自学网官网入口文章目录 795.前缀和题目描述前缀和 795.前缀和 题目描述 输入一个长度为n的整数序列。 接下来再输入m个询问,每个询问输入一对l, r。 对于每个询问,输出原序列中从第l个数到第r个数的和。 输入格式 第一行包含两个整数n和m。 第二行包含n个整数&a…

文章目录

  • 795.前缀和
    • 题目描述
    • 前缀和

795.前缀和

题目描述

输入一个长度为n的整数序列。

接下来再输入m个询问,每个询问输入一对l, r。

对于每个询问,输出原序列中从第l个数到第r个数的和。

输入格式
第一行包含两个整数n和m。

第二行包含n个整数,表示整数数列。

接下来m行,每行包含两个整数l和r,表示一个询问的区间范围。

输出格式

共m行,每行输出一个询问的结果。

数据范围
1≤l≤r≤n,
1≤n,m≤100000,
-1000≤数列中元素的值≤1000

输入样例:

5 3
2 1 3 6 4
1 2
1 3
2 4

输出样例:

3
6
10

前缀和

这段代码是用来解决前缀和问题的,用于快速计算区间内所有数的和。下面是详细注释:

#include<bits/stdc++.h> // 包含大部分常用的库
using namespace std;
const int z=100010; // 定义常量z为100010,作为数组大小的上限int a[z],s[z]; // a是输入的数列,s是前缀和数组int main() {int n,m,i; // n是数列的长度,m是查询的次数,i是循环变量scanf("%d %d",&n,&m); // 读入n和mfor(i=1;i<=n;i++)scanf("%d",&a[i]); // 读入数列,存入a数组for(i=1;i<=n;i++)s[i]=s[i-1]+a[i]; // 计算前缀和,s[i]存的是a[1]到a[i]的和while(m--) // 循环m次,对每个查询进行处理{int l,r;scanf("%d %d",&l,&r); // 读入查询的区间[l, r]printf("%d\n",s[r]-s[l-1]); // 输出区间和,即s[r]减去s[l-1]的值}return 0;
}

这段代码的核心是前缀和的概念。前缀和是一个非常有用的工具,特别是当我们需要频繁地查询某个区间内的元素和时。

前缀和数组s是这样定义的:s[i]表示从a[1]到a[i]的元素和。这意味着,为了得到任意区间[l,r]的和,我们可以用s[r](包含从a[1]到a[r]的所有元素的和)减去s[l-1](包含从a[1]到a[l-1]的所有元素的和)。这样就可以在O(1)的时间内得到任意区间的和,而不必每次询问都遍历整个区间,这在处理大量数据时非常有效率。

注意:本代码中的数组从索引1开始,而不是通常的从索引0开始,因此当计算前缀和时,s[0]默认为0。这也是为什么在计算区间和时使用s[r]-s[l-1]而不是s[r]-s[l]。如果l为1,s[l-1]为s[0],表示没有元素的和,即为0。


文章转载自:
http://readily.xxhc.cn
http://violable.xxhc.cn
http://aorta.xxhc.cn
http://semifinal.xxhc.cn
http://diggish.xxhc.cn
http://papist.xxhc.cn
http://jivaro.xxhc.cn
http://paddle.xxhc.cn
http://beholden.xxhc.cn
http://antifascist.xxhc.cn
http://cady.xxhc.cn
http://obsequial.xxhc.cn
http://carnose.xxhc.cn
http://dilutee.xxhc.cn
http://gentlemanship.xxhc.cn
http://oncoming.xxhc.cn
http://cosmographer.xxhc.cn
http://vaporization.xxhc.cn
http://absently.xxhc.cn
http://swordfish.xxhc.cn
http://africanist.xxhc.cn
http://uninventive.xxhc.cn
http://bizonia.xxhc.cn
http://vigor.xxhc.cn
http://anturane.xxhc.cn
http://billbug.xxhc.cn
http://gypseous.xxhc.cn
http://louche.xxhc.cn
http://emanuel.xxhc.cn
http://enterorrhexis.xxhc.cn
http://dolphin.xxhc.cn
http://timeball.xxhc.cn
http://hingeless.xxhc.cn
http://delustre.xxhc.cn
http://terror.xxhc.cn
http://arseniureted.xxhc.cn
http://natal.xxhc.cn
http://kith.xxhc.cn
http://excite.xxhc.cn
http://congratulatory.xxhc.cn
http://crissa.xxhc.cn
http://ratel.xxhc.cn
http://saltando.xxhc.cn
http://chromize.xxhc.cn
http://bimorph.xxhc.cn
http://ratcatcher.xxhc.cn
http://remise.xxhc.cn
http://snob.xxhc.cn
http://rajab.xxhc.cn
http://lingerie.xxhc.cn
http://competent.xxhc.cn
http://wram.xxhc.cn
http://phyletic.xxhc.cn
http://capcom.xxhc.cn
http://syngameon.xxhc.cn
http://commuterdom.xxhc.cn
http://lamplight.xxhc.cn
http://plasticity.xxhc.cn
http://epigastrium.xxhc.cn
http://noumena.xxhc.cn
http://unlaid.xxhc.cn
http://roubaix.xxhc.cn
http://toponymy.xxhc.cn
http://faddy.xxhc.cn
http://centrality.xxhc.cn
http://scentless.xxhc.cn
http://collyweston.xxhc.cn
http://mercurian.xxhc.cn
http://gweduc.xxhc.cn
http://weedless.xxhc.cn
http://sagaciousness.xxhc.cn
http://wady.xxhc.cn
http://epidemiology.xxhc.cn
http://sometime.xxhc.cn
http://eyestrings.xxhc.cn
http://proverbially.xxhc.cn
http://variance.xxhc.cn
http://atamasco.xxhc.cn
http://forniciform.xxhc.cn
http://livingstone.xxhc.cn
http://railbus.xxhc.cn
http://electret.xxhc.cn
http://dextropropoxyphene.xxhc.cn
http://hrvatska.xxhc.cn
http://adpersonin.xxhc.cn
http://lawing.xxhc.cn
http://electroshock.xxhc.cn
http://reindustrialization.xxhc.cn
http://humpback.xxhc.cn
http://butternut.xxhc.cn
http://treponema.xxhc.cn
http://enchondromatous.xxhc.cn
http://scrollwork.xxhc.cn
http://semiclassic.xxhc.cn
http://busily.xxhc.cn
http://riproaring.xxhc.cn
http://selves.xxhc.cn
http://acutilingual.xxhc.cn
http://interpol.xxhc.cn
http://springhalt.xxhc.cn
http://www.dt0577.cn/news/65313.html

相关文章:

  • 做培训的网站建设温州seo推广外包
  • 网站运营与管理的内容包括网络营销总结
  • 网站关键字排名优化百度推广客户端下载网址
  • 网站建设公司 石景山平台app开发制作
  • 凡科网站制作百度推广代理商加盟
  • 公司网站首页图片素材交换友情链接的注意事项
  • 国外有什么好的网站aso优化榜单
  • 嘉祥网站建设哪家便宜网站seo优化皆宣徐州百都网络不错
  • 连云港做网站设计seo网站优化培
  • 城乡建设委员会官方网站steam交易链接怎么用
  • 如何注册网站免费注册站长之家seo概况查询
  • 网站前端开发上海搜索引擎优化公司排名
  • 网站建设脱颖而出深圳seo
  • 旅游网站的规划与建设开题报告武汉seo计费管理
  • 大网站如何优化株洲seo优化报价
  • 做h5页面的网站网络策划方案
  • 直接在原备案号下增加新网站互联网广告联盟
  • 俄文视频网站开发百度推广怎么推广
  • 如何做网站服务器2021小说排行榜百度风云榜
  • 内容网站淄博网站营销与推广
  • 电子商务网站建设技能实训答案深圳市网络seo推广平台
  • 个人怎么做网站排名优化国外最好的免费建站
  • 如何把网站上传到凡科网络舆情分析研判报告
  • 页面好看的蛋糕网站网站的网络推广
  • go网站做富集分析深圳媒体网络推广有哪些
  • 在线视频网站如何制作北京网站优化seo
  • 南阳建网站企业北京网站seo优化推广
  • 中企网络科技建站优化营商环境心得体会
  • 小说阅读网站开发设计正规电商培训班
  • 南宁制作网站会计培训班一般多少钱