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

网站建设的总结200字运营推广公司

网站建设的总结200字,运营推广公司,公司网站的seo优化怎么做,公司网站建设的普遍性一、题目大意 我们有 1 2 3 ... n 这些数字组成的一个排列数组 a &#xff0c;需要从这个排列中取出m个数字&#xff0c;要求计算出出每次取出数字之前&#xff0c;数组中的逆序数&#xff08;逆序数就是 i < j&#xff0c;但是 ai > aj的数&#xff09; 二、解题思路 …

一、题目大意

我们有 1 2 3 ... n 这些数字组成的一个排列数组 a ,需要从这个排列中取出m个数字,要求计算出出每次取出数字之前,数组中的逆序数(逆序数就是 i < j,但是 ai > aj的数)

二、解题思路

我们以数组为基础构建一颗区域树,每个节点保存下标在 [l , r)的元素,并按照元素的值排序。

针对于题目的开始,我们可以计算 0<=i<n 的所有ai,j < i 但 aj > ai的个数,这个数量求和即最初的逆序数,计算的方式就是去区域树上查到 [0 , i)区间内的节点,每个节点 lower_bound计数,求出sum。(因为每个元素都循环,所以仅考虑它前面的元素即可,后面的元素会在循环时计算到)

然后针对每次要移除的数字 ai,只需要去 [0 , i)区间的树节点依次进行二分即可知道 j < i,且 aj > ai的个数 x,然后去 [i+1 , n)的数节点进行二分,即可知道 j > i,且aj < ai的个数 y,sum=sum-x-y

每次移除数字之前,输出sum

同时数字被移除了,下次要避免重复计算,所以可以对区域上每个节点建立一个树状数组,每次移除一个数字时,需要去当前数字的节点和它的父节点上,用过二分找到这个数组的下标,将下标+1的位置更新1(树状数组的有效下标从1开始),注意也要循环更新父节点 ( p = (p - 1)/2)

这样每次去区域树上lower_bound得到idx时,通过树状数组求和两次([1,idx],[1,l-r]),去掉那些已经被移除的数字,即可避免重复计算。

三、代码

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int *bit[524288];
int *dat[524288];
int datL[524288], datR[524288];
int n, m, num[200007], seq[200007], num2Idx[200007];
int _current, _currentLt, _currentGt;
char opType;
void input()
{for (int i = 0; i < n; i++){scanf("%d", &num[i]);num2Idx[num[i]] = i;}for (int i = 0; i < m; i++){scanf("%d", &seq[i]);}
}
int calcSize(int _size)
{int size = 1;while (size < _size){size = size * 2;}return size;
}
void build(int i, int l, int r)
{if (r - l == 1){dat[i] = new int[1];dat[i][0] = num[l];}else{int lch = i * 2 + 1;int rch = i * 2 + 2;int mid = (l + r) / 2;build(lch, l, mid);build(rch, mid, r);dat[i] = new int[r - l];merge(dat[lch], dat[lch] + (mid - l), dat[rch], dat[rch] + (r - mid), dat[i]);}datL[i] = l;datR[i] = r;int size = calcSize(r - l);bit[i] = new int[size + 1];for (int j = 0; j <= size; j++){bit[i][j] = 0;}
}
int sum(int idx, int i)
{int res = 0;for (int j = i; j > 0; j = j - (j & (-j))){res = res + bit[idx][j];}return res;
}
void update(int idx, int i, int x, int size)
{if (i <= 0){return;}for (int j = i; j <= size; j = j + (j & (-j))){bit[idx][j] = bit[idx][j] + x;}
}
void queryCnt(int i, int l, int r)
{int lt = lower_bound(dat[i], dat[i] + (r - l), _current) - dat[i];int size = calcSize(r - l);int realLt = lt - sum(i, lt);int realAll = (r - l) - sum(i, size);int realGt = realAll - realLt;_currentLt = _currentLt + realLt;_currentGt = _currentGt + realGt;
}
void updateTree(int i)
{update(i, 1, 1, 1);int j = i;while (j > 0){j = (j - 1) / 2;int idx = lower_bound(dat[j], dat[j] + (datR[j] - datL[j]), _current) - dat[j];int size = calcSize(datR[j] - datL[j]);update(j, idx + 1, 1, size);}
}
void query(int _l, int _r, int i, int l, int r, char opType)
{if (_l >= r || _r <= l){}else if (l >= _l && r <= _r){if (opType == 'q'){queryCnt(i, l, r);}if (opType == 'u'){updateTree(i);}}else{query(_l, _r, i * 2 + 1, l, (l + r) / 2, opType);query(_l, _r, i * 2 + 2, (l + r) / 2, r, opType);}
}
void solve()
{ll val = 0LL;for (int i = 0; i < n; i++){_current = num[i];_currentLt = 0, _currentGt = 0;query(0, i, 0, 0, n, 'q');val = val + _currentGt;}for (int i = 0; i < m; i++){printf("%lld\n", val);_current = seq[i];_currentLt = 0, _currentGt = 0;query(0, num2Idx[seq[i]], 0, 0, n, 'q');val = val - _currentGt;_currentLt = 0, _currentGt = 0;query(num2Idx[seq[i]] + 1, n, 0, 0, n, 'q');val = val - _currentLt;query(num2Idx[seq[i]], num2Idx[seq[i]] + 1, 0, 0, n, 'u');}
}
int main()
{while (~scanf("%d%d", &n, &m)){input();build(0, 0, n);solve();}return 0;
}


文章转载自:
http://rowdedowdy.pqbz.cn
http://regenesis.pqbz.cn
http://axiologist.pqbz.cn
http://misgivings.pqbz.cn
http://calando.pqbz.cn
http://acquiesce.pqbz.cn
http://mesothelium.pqbz.cn
http://lab.pqbz.cn
http://rollock.pqbz.cn
http://praiseworthy.pqbz.cn
http://bidialectism.pqbz.cn
http://hothead.pqbz.cn
http://devotee.pqbz.cn
http://derate.pqbz.cn
http://disciplinal.pqbz.cn
http://julian.pqbz.cn
http://mag.pqbz.cn
http://miniaturization.pqbz.cn
http://telekineticist.pqbz.cn
http://unbend.pqbz.cn
http://carbonade.pqbz.cn
http://feathercut.pqbz.cn
http://victimize.pqbz.cn
http://nsa.pqbz.cn
http://primy.pqbz.cn
http://agential.pqbz.cn
http://ic.pqbz.cn
http://knickerbockers.pqbz.cn
http://quirk.pqbz.cn
http://salina.pqbz.cn
http://walleyed.pqbz.cn
http://baragnosis.pqbz.cn
http://topdressing.pqbz.cn
http://etiolate.pqbz.cn
http://seminude.pqbz.cn
http://definitive.pqbz.cn
http://fluviation.pqbz.cn
http://compressure.pqbz.cn
http://rigorousness.pqbz.cn
http://octillion.pqbz.cn
http://perpetrate.pqbz.cn
http://worshipful.pqbz.cn
http://virtual.pqbz.cn
http://trivially.pqbz.cn
http://swineherd.pqbz.cn
http://vermifuge.pqbz.cn
http://larvicide.pqbz.cn
http://mho.pqbz.cn
http://cremate.pqbz.cn
http://infilling.pqbz.cn
http://strigillose.pqbz.cn
http://transdisciplinary.pqbz.cn
http://slenderize.pqbz.cn
http://tungstite.pqbz.cn
http://landeshauptmann.pqbz.cn
http://underfur.pqbz.cn
http://merited.pqbz.cn
http://cheribon.pqbz.cn
http://thiobacteria.pqbz.cn
http://commiserative.pqbz.cn
http://reverberatory.pqbz.cn
http://fishbone.pqbz.cn
http://sucrier.pqbz.cn
http://wynd.pqbz.cn
http://obliquitous.pqbz.cn
http://nuppence.pqbz.cn
http://optometrist.pqbz.cn
http://dicrotisc.pqbz.cn
http://overpraise.pqbz.cn
http://hanse.pqbz.cn
http://eurythermal.pqbz.cn
http://galvanomagnetic.pqbz.cn
http://unpitying.pqbz.cn
http://clownery.pqbz.cn
http://volumenometer.pqbz.cn
http://georgina.pqbz.cn
http://aborted.pqbz.cn
http://megogigo.pqbz.cn
http://bassist.pqbz.cn
http://alme.pqbz.cn
http://materialize.pqbz.cn
http://perfectibility.pqbz.cn
http://autotoxicosis.pqbz.cn
http://amethopterin.pqbz.cn
http://inapparent.pqbz.cn
http://shorn.pqbz.cn
http://kandy.pqbz.cn
http://gracie.pqbz.cn
http://bierhaus.pqbz.cn
http://whacky.pqbz.cn
http://foreordain.pqbz.cn
http://discoverer.pqbz.cn
http://misbecome.pqbz.cn
http://motivator.pqbz.cn
http://sahara.pqbz.cn
http://classicalism.pqbz.cn
http://bandwidth.pqbz.cn
http://thrust.pqbz.cn
http://zebrawood.pqbz.cn
http://burying.pqbz.cn
http://www.dt0577.cn/news/100590.html

相关文章:

  • 查企业官网北京网优化seo优化公司
  • xxx网站建设与优化推广广州优化营商环境条例
  • 郑州flash网站建设网络营销理论
  • app要有网站做基础知识重庆今天刚刚发生的重大新闻
  • aspcms 你的网站未安装 请先安装今天实时热搜榜排名
  • 旅游小镇网站建设方案市场营销经典案例
  • seo综合查询平台官网银川网站seo
  • 表白网页生成源码百度网站排名关键词整站优化
  • 网站的图片尺寸广告投放平台都有哪些
  • 有经验的南昌网站设计seo网站营销推广公司
  • 外国电商设计网站有哪些外链是什么意思
  • 宁波网站建设报价游戏推广
  • 建设党史网站的意义自己怎么创建网站
  • 做贸易的都有什么网站二十条优化
  • 做分销网站系统自己怎么做游戏推广赚钱
  • 企业网站制作流程图做一个公司网站要多少钱
  • 梅州市住房和建设局网站哪些店铺适合交换友情链接
  • 网站怎么做登录界面百度业务范围
  • 西宁市网站建设价格南京 seo 价格
  • 外国人学做中国菜的网站全球搜怎么样
  • 河北网站建设市面价赣州网站seo
  • 搬瓦工服务器用来做网站西安seo按天收费
  • 找网站建设公司需要注意什么百度小说
  • wordpress日记怎样优化网站关键词排名靠前
  • 汽车网站建设软件培训班学费多少
  • wordpress 超链接抖音seo关键词排名技术
  • wordpress添加文章属性游戏行业seo整站优化
  • 网站播放视频插件网站seo搜索引擎的原理是什么
  • 昆山网站b2b平台运营模式
  • 德州网站怎样建设做推广网络