【题目链接】

点击打开链接

【算法】

树状数组

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010 int n,i,x;
long long ans;
int pos[MAXN];
long long c[MAXN]; inline int lowbit(int x)
{
return x & (-x);
}
inline void modify(int pos,long long val)
{
int i;
for (i = pos; i <= * n; i += lowbit(i)) c[i] += val;
}
inline long long query(int pos)
{
int i;
long long ans = ;
for (i = pos; i; i -= lowbit(i)) ans += c[i];
return ans;
}
inline long long query(int l,int r)
{
return query(r) - query(l-);
} int main() { scanf("%d",&n);
for (i = ; i <= * n; i++)
{
scanf("%d",&x);
if (!pos[x])
{
pos[x] = i;
modify(i,);
} else
{
ans += query(pos[x]+,i-);
modify(pos[x],-);
}
}
printf("%lld\n",ans); return ; }

最新文章

  1. 【IScroll深入学习】解决IScroll疑难杂症
  2. Thenao tutorial – indexing
  3. Visual C#两分钟搭建BHO IE钩子(转)
  4. CoderForces 280B(记忆化搜索)
  5. Educational Codeforces Round 3 E (609E) Minimum spanning tree for each edge
  6. [Buffalo]MVC架构模式
  7. EF FluentAPI映射一对多 关系时候报错
  8. 破译情报-NOIP2016提高组复赛模拟试题
  9. 了解 : 怎么处理jobbox status drop down list roll back
  10. ActiveReports 6:如何升级旧版本的项目
  11. ElasticSearch之 控制相关度原理讲解
  12. Linux的eth0,eth1,eth2,lo详解
  13. mysql 通过测试&#39;for update&#39;,深入了解行锁、表锁、索引
  14. random-----随机数
  15. 32.Mysql Cluster
  16. 【HDU5831】Rikka with Parenthesis II(括号)
  17. 在react+redux+axios项目中使用async/await
  18. winform 与百度搜索智能提示
  19. JVM调优——之CMS GC日志分析
  20. Python中如何获取类属性的列表

热门文章

  1. JavaScript中的特殊数据类型
  2. Java ExecutorService四种线程池的例子与说明(转发)
  3. Orcad中较好的习惯背景
  4. 关于meta标签的使用,属性的说明
  5. 九度oj 题目1077:最大序列和
  6. [K/3Cloud] 创建一个单据转换插件
  7. android开发里跳过的坑-android studio 错误 Could not find junit:junit:4.12
  8. Linux下汇编语言学习笔记21 ---
  9. hdu - 2645 find the nearest station (bfs水)
  10. POJ 3686_The Windy&#39;s