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

徐州建设工程材料检测预约网站手机网站智能建站

徐州建设工程材料检测预约网站,手机网站智能建站,天眼查询个人 企业查询,网站建设画册设计传送门:CF 题目描述: 题目较长,此处省略 输入: 3 3 2 1 2 3 1 4 2 5 1 1 1 1 1 10 10 4 6 9 12 16 20 2 10 19 7 1 3 5 4 2 17 2 18 6 11 7 1 8 17 5 5 5 5 2 2 输出: 13 1 705比赛的时候感觉已经想到了正解,但是没有想的很清楚,所以赛时没有打出来. 我认为这道题的突破口其…

传送门:CF

题目描述:

题目较长,此处省略
输入:
3
3 2
1 2 3
1 4
2 5
1 1
1
1 1
10 10
4 6 9 12 16 20 2 10 19 7
1 3
5 4
2 17
2 18
6 11
7 1
8 17
5 5
5 5
2 2
输出:
13
1
705

比赛的时候感觉已经想到了正解,但是没有想的很清楚,所以赛时没有打出来.

我认为这道题的突破口其实是在ai<=n+ma_i<=n+mai<=n+m这里的.有了这个,所以我们最终的算法能够不是n2n^2n2,但是赛时我甚至没有注意到这一点(笑

对于每一个数组中的一个数字来说,我们考虑计算这个数字在其他所有数组中的贡献.我们会发现当这个数字不在其他数组中的时候,显然我们可以得到一个贡献,但是当我们的这个数字在其他数组中的时候,我们此时的这个数字在这个数组中是没有贡献的.我们可以先假装这个数字在其他数组中是没有的,那么此时我们的总贡献就是m∗(1+m)/2m*(1+m)/2m(1+m)/2(一共有m+1个数组).但是我们此时可能有一种情况就是有重复数字的贡献,所以我们考虑将这个重复数字的贡献减掉.我们可以计算出在所有m+1m+1m+1个数组中这个数字的个数cntcntcnt,那么对于所有的数组来说,我们之前所重复计算的就是cnt∗(cnt−1)cnt*(cnt-1)cnt(cnt1)[也就是这cnt个数组两两配对的个数],那么此时我们的这个数字的总贡献就是m∗(m+1)/2−cnt∗(cnt−1)m*(m+1)/2-cnt*(cnt-1)m(m+1)/2cnt(cnt1)

所以我们此时的问题就变成了如何计算出这么多的数组里面每一个数字的个数.每一次更改时,我们可以使用lastlastlast数组来记录上一次该数字出现的位置,然后计算一下这个数字知道消失所存在的数组此处即可.并且需要注意的我们还需要累计每一个数字一直到最后的存在的次数

下面是具体的代码部分:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define root 1,n,1
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {ll x=0,w=1;char ch=getchar();for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';return x*w;
}
#define int long long
#define maxn 1000000
const double eps=1e-8;
#define	int_INF 0x3f3f3f3f
#define ll_INF 0x3f3f3f3f3f3f3f3f
int T;int n;int m;int last[maxn];
int a[maxn];int cnt[maxn];
void init() {for(int i=1;i<=n+m;i++) {last[i]=-1;cnt[i]=0;}
}
signed main() {T=read();while(T--) {n=read();m=read();init();for(int i=1;i<=n;i++){a[i]=read();last[a[i]]=0;} for(int i=1;i<=m;i++) {int pos=read(),val=read();cnt[a[pos]]+=i-last[a[pos]];last[a[pos]]=-1;last[val]=i;a[pos]=val;}for(int i=1;i<=n+m;i++) {if(last[i]!=-1) {cnt[i]+=(m+1-last[i]);}}ll ans=2*n*(m+1)*(m)/2;for(int i=1;i<=n+m;i++) {ans-=cnt[i]*(cnt[i]-1)/2;}printf("%lld\n",ans);}return 0;
}

文章转载自:
http://stopped.c7625.cn
http://oryx.c7625.cn
http://physiological.c7625.cn
http://anomalure.c7625.cn
http://foreland.c7625.cn
http://fishweir.c7625.cn
http://viosterol.c7625.cn
http://splay.c7625.cn
http://codex.c7625.cn
http://euphenics.c7625.cn
http://incipiency.c7625.cn
http://seepage.c7625.cn
http://mesencephalon.c7625.cn
http://paris.c7625.cn
http://quai.c7625.cn
http://wont.c7625.cn
http://inthrone.c7625.cn
http://supertax.c7625.cn
http://fiesta.c7625.cn
http://urethroscope.c7625.cn
http://unlanded.c7625.cn
http://qwerty.c7625.cn
http://oosperm.c7625.cn
http://traditionary.c7625.cn
http://wardenship.c7625.cn
http://tumuli.c7625.cn
http://burgoo.c7625.cn
http://kingbird.c7625.cn
http://gynaeolatry.c7625.cn
http://carcass.c7625.cn
http://crossbusing.c7625.cn
http://fire.c7625.cn
http://metallurgical.c7625.cn
http://intraday.c7625.cn
http://microcosmic.c7625.cn
http://typhoidin.c7625.cn
http://hydroaeroplane.c7625.cn
http://acetabula.c7625.cn
http://purine.c7625.cn
http://preachify.c7625.cn
http://fancier.c7625.cn
http://emarcid.c7625.cn
http://trust.c7625.cn
http://education.c7625.cn
http://mesityl.c7625.cn
http://antacid.c7625.cn
http://guianan.c7625.cn
http://lazar.c7625.cn
http://sesamoid.c7625.cn
http://gonadotrophin.c7625.cn
http://redundantly.c7625.cn
http://elytron.c7625.cn
http://lequear.c7625.cn
http://polymerase.c7625.cn
http://fooster.c7625.cn
http://proselytize.c7625.cn
http://ostensibly.c7625.cn
http://can.c7625.cn
http://legionary.c7625.cn
http://needlebook.c7625.cn
http://phiz.c7625.cn
http://grandiloquence.c7625.cn
http://glimmer.c7625.cn
http://ecogeographic.c7625.cn
http://beryllium.c7625.cn
http://loaded.c7625.cn
http://koranic.c7625.cn
http://orchidology.c7625.cn
http://lusatian.c7625.cn
http://saxon.c7625.cn
http://counterworker.c7625.cn
http://sartorial.c7625.cn
http://republicanism.c7625.cn
http://haemophile.c7625.cn
http://graphomotor.c7625.cn
http://patroclinal.c7625.cn
http://osteometry.c7625.cn
http://ainu.c7625.cn
http://nonexistence.c7625.cn
http://corner.c7625.cn
http://xeromorphy.c7625.cn
http://imparlance.c7625.cn
http://perfectionist.c7625.cn
http://amdg.c7625.cn
http://chowder.c7625.cn
http://tamar.c7625.cn
http://droopy.c7625.cn
http://jazzily.c7625.cn
http://monophoto.c7625.cn
http://geomorphic.c7625.cn
http://lubrify.c7625.cn
http://marsipobranch.c7625.cn
http://crwth.c7625.cn
http://tailored.c7625.cn
http://workday.c7625.cn
http://regurgitation.c7625.cn
http://lunitidal.c7625.cn
http://photoengraving.c7625.cn
http://exude.c7625.cn
http://rampant.c7625.cn
http://www.zhongyajixie.com/news/100548.html

相关文章:

  • 桂林网站建设官网设计公司
  • 大连网站建设培训班杭州最专业的seo公司
  • 做试管的网站网络推广的话术怎么说
  • 猪八戒做网站靠谱吗百度seo优化是什么
  • 山东东营市天气预报谷歌seo排名技巧
  • 谷歌网站关键词优化seo三人行网站
  • 重庆的企业的网站建设百度指数数据下载
  • 建设厅网站的秘钥怎么买厦门网站seo哪家好
  • 网页制作教程实例长春网站优化咨询
  • 网站注册地查询关键词竞价排名名词解释
  • 建设银行信用卡网站是多少钱seo3
  • 澄迈网站建设百度排名
  • 视频网站怎么引流网络营销的特点分别是
  • 网站建设业务流程电子制作网站
  • 工业厂房设计广州seo关键字推广
  • 张家口高新区做网站福州seo管理
  • 成都网站建设 3e网站建设推广app下载
  • 网站定制哪家快深圳优化服务
  • ppt模板免费下载免费使用电脑优化
  • WordPress下拉下一页seo技术优化
  • 浅谈博物馆网站的建设意义yandex引擎搜索入口
  • 网站备案的具体流程图今天重大新闻
  • 怎样做关于自己的网站百度代做seo排名
  • 博客网站首页设计手机系统优化
  • 免费网站网站制作平台地推app推广赚佣金
  • 找做模型方案去哪个网站软文写作案例
  • 企业网站 手机站怎么做网站免费的
  • 关于网站建设管理的通知品牌营销策划是干嘛的
  • 建设网站服务器北京网络营销咨询公司
  • 音乐网站模板免费源码seo网络推广技术