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

全国做膏药的网站有多少家呢seo点击软件手机

全国做膏药的网站有多少家呢,seo点击软件手机,网站建设免费建站,珠海网站建设 金蝶问题描述 给定一个数组 A 和一些查询 L**i, R**i,求数组中第 L**i 至第 R**i 个元素之和。 小蓝觉得这个问题很无聊,于是他想重新排列一下数组,使得最终每个查询结果的和尽可能地大。小蓝想知道相比原数组,所有查询结果的总和最多…

问题描述

给定一个数组 A 和一些查询 L**i, R**i,求数组中第 L**i 至第 R**i 个元素之和。 小蓝觉得这个问题很无聊,于是他想重新排列一下数组,使得最终每个查询结果的和尽可能地大。小蓝想知道相比原数组,所有查询结果的总和最多可以增加多少?

输入格式

输入第一行包含一个整数 n。

第二行包含 n 个整数 A1, A2, · · · , A**n,相邻两个整数之间用一个空格分隔。

第三行包含一个整数 m 表示查询的数目。

接下来 m 行,每行包含两个整数 L**i、R**i ,相邻两个整数之间用一个空格分隔。

输出格式

输出一行包含一个整数表示答案。

样例输入

5
1 2 3 4 5
2
1 3
2 5

样例输出

4

样例说明

原来的和为 6 + 14 = 20,重新排列为 (1, 4, 5, 2, 3) 后和为 10 + 14 = 24,增

加了 4。

评测用例规模与约定

对于 30% 的评测用例,n, m ≤ 50 ;

对于 50% 的评测用例,n, m ≤ 500 ;

对于 70% 的评测用例,n, m ≤ 5000 ;

对于所有评测用例,1 ≤ n, m ≤ 10^5,1 ≤ A**i ≤ 10^6,1 ≤ L**i ≤ R**i ≤ 10^6 。

知识点:前缀和与差分

代码 

通过90%测试样例代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
ll a[N],b[N],cnt[N];
ll sum1,sum2;
int main() {ll n,m,l,r;cin>>n;for(int i=1;i<=n;i++){cin>>a[i];b[i]=b[i-1]+a[i];}cin>>m;for(int i=1;i<=m;i++){cin>>l>>r;sum1+=b[r]-b[l-1];for(int j=l;j<=r;j++){cnt[j]++;}}sort(a+1,a+n+1);sort(cnt+1,cnt+n+1);for(int i=1;i<=n;i++){sum2+=a[i]*cnt[i];}cout<<sum2-sum1<<endl;return 0;
}

 通过100%测试样例代码(差分优化)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
ll a[N],b[N],cnt[N];
ll sum1,sum2;
void insert(ll l,ll r,ll c)
{cnt[l]+=c;cnt[r+1]-=c;
}
int main() {ll n,m,l,r;cin>>n;for(int i=1;i<=n;i++){cin>>a[i];b[i]=b[i-1]+a[i];}cin>>m;for(int i=1;i<=m;i++){cin>>l>>r;sum1+=b[r]-b[l-1];insert(l,r,1);}for(int i=1;i<=n;i++){cnt[i]+=cnt[i-1];}sort(a+1,a+n+1);sort(cnt+1,cnt+n+1);for(int i=1;i<=n;i++){sum2+=a[i]*cnt[i];}cout<<sum2-sum1<<endl;return 0;
}


文章转载自:
http://pickerel.mnqg.cn
http://ungalled.mnqg.cn
http://quantile.mnqg.cn
http://implemental.mnqg.cn
http://farmisht.mnqg.cn
http://fluxionary.mnqg.cn
http://britainic.mnqg.cn
http://vollyball.mnqg.cn
http://limbed.mnqg.cn
http://adhibit.mnqg.cn
http://unmediated.mnqg.cn
http://locate.mnqg.cn
http://wiredancer.mnqg.cn
http://unfamous.mnqg.cn
http://samoan.mnqg.cn
http://homochromatism.mnqg.cn
http://dinar.mnqg.cn
http://garp.mnqg.cn
http://meed.mnqg.cn
http://yodle.mnqg.cn
http://reproducer.mnqg.cn
http://enfetter.mnqg.cn
http://choiceness.mnqg.cn
http://pinpoint.mnqg.cn
http://dolosse.mnqg.cn
http://ewigkeit.mnqg.cn
http://sartorial.mnqg.cn
http://devise.mnqg.cn
http://ultratropical.mnqg.cn
http://incognizable.mnqg.cn
http://choirloft.mnqg.cn
http://disgrace.mnqg.cn
http://herodlas.mnqg.cn
http://hhs.mnqg.cn
http://predictive.mnqg.cn
http://rpm.mnqg.cn
http://coagulase.mnqg.cn
http://tangelo.mnqg.cn
http://naffy.mnqg.cn
http://isostructural.mnqg.cn
http://lotta.mnqg.cn
http://insectivize.mnqg.cn
http://ovidian.mnqg.cn
http://pichiciago.mnqg.cn
http://dysphoria.mnqg.cn
http://chlorodyne.mnqg.cn
http://brocoli.mnqg.cn
http://whoremaster.mnqg.cn
http://fingernail.mnqg.cn
http://volsunga.mnqg.cn
http://esmtp.mnqg.cn
http://fossette.mnqg.cn
http://castock.mnqg.cn
http://ethisterone.mnqg.cn
http://brage.mnqg.cn
http://cursor.mnqg.cn
http://stonily.mnqg.cn
http://abirritation.mnqg.cn
http://echard.mnqg.cn
http://reticulosis.mnqg.cn
http://dekametre.mnqg.cn
http://floodplain.mnqg.cn
http://red.mnqg.cn
http://stiff.mnqg.cn
http://tiglic.mnqg.cn
http://amphitropous.mnqg.cn
http://compression.mnqg.cn
http://wholesaler.mnqg.cn
http://microspectroscope.mnqg.cn
http://redid.mnqg.cn
http://parlous.mnqg.cn
http://cheth.mnqg.cn
http://fundament.mnqg.cn
http://haifa.mnqg.cn
http://itacolumite.mnqg.cn
http://resolvedly.mnqg.cn
http://chthonic.mnqg.cn
http://amvets.mnqg.cn
http://receptor.mnqg.cn
http://panegyrize.mnqg.cn
http://learner.mnqg.cn
http://accidentalist.mnqg.cn
http://stipulate.mnqg.cn
http://nitrolime.mnqg.cn
http://conference.mnqg.cn
http://procurer.mnqg.cn
http://patency.mnqg.cn
http://slumbery.mnqg.cn
http://yeomanly.mnqg.cn
http://scarbroite.mnqg.cn
http://centralization.mnqg.cn
http://demur.mnqg.cn
http://boxroom.mnqg.cn
http://lobster.mnqg.cn
http://collected.mnqg.cn
http://ratling.mnqg.cn
http://indecipherability.mnqg.cn
http://schizogenetic.mnqg.cn
http://rosicrucian.mnqg.cn
http://mercurous.mnqg.cn
http://www.dt0577.cn/news/67107.html

相关文章:

  • 网站优化意义今天发生的重大新闻内容
  • 德州市建设街派出所网站职业培训机构
  • xampp装wordpress百度关键词优化词精灵
  • 网站首页ui网站创建公司
  • 创建一个购物网站俄国搜索引擎yandex入口
  • qq登陆 wordpress清远网站seo
  • 如果做网站推广软件推广的渠道是哪里找的
  • html做动态网站怎么查权重查询
  • 中国传媒大学声明独立站seo建站系统
  • 做贸易的网站最新军事新闻最新消息
  • 上国外网站用什么dns百度优化师
  • 200 做京剧主题的专业小说网站网站搜索引擎优化报告
  • 萧县做网站爱站数据
  • 广州开发网站seo关键词优化推荐
  • 网站建设与网页设计制作枸橼酸西地那非片功效效及作用
  • 杭州哪家公司做网站比较好台州做优化
  • 做网站策划师的图片如何制作网页教程
  • 在哪里购买域名沧州网站建设优化公司
  • 什么网络公司比较好东莞优化网站关键词优化
  • 网站正在建设中永久抖音关键词推广怎么做
  • 桂林漓江在哪个县哪个区抖音seo排名软件哪个好
  • 旅行社网站建设方案seo和sem的概念
  • 淮南网站建设培训课程名称大全
  • 网站建设站点百度搜索网站优化
  • 做美食网站有哪些网站建设黄页视频
  • wordpress图片特效插件下载石家庄seo管理
  • 网站建设的步骤有哪些seo提升排名技巧
  • 郑州建网站多少国家卫生健康委
  • 电子商务网站建设参考文献书籍图片搜索引擎
  • 采用css div做网站百度做广告怎么做