Codeforces Round #261 (Div. 2) D 树状数组应用
来源:互联网 发布:猫眼数据 编辑:程序博客网 时间:2024/05/24 04:30
看着题意:[1,i]中等于a[i]的个数要大于[,jn]中等于a[j]的个数 且i<j,求有多少对这样的(i,j) ,i<j但是 i前面的合法个数 要大于j后面的 看起来很像逆序数的样子,所以很容易往树状数组想去,但是处理就看个人了,像我比赛的时候就处理得非常的麻烦,虽做出了但是花时间也多,经过杰哥的教育,其实正着塞进树状数组 反着来找就可以了,灰常的简单清晰明了,贴一发纪念我的搓比...
int n;int aa[1000000 + 55];int bb[1000000 + 55];int c[1000000 + 55];map<int ,int >mp;ll lowbit(ll x) {return x&(-x);}void add(int i,int val) {while(i <= n) {c[i] += val;i += lowbit(i);}}ll get_sum(int i) {ll sum = 0;while(i) {sum += c[i];i -= lowbit(i);}return sum;}void init() {memset(c,0,sizeof(c));memset(aa,0,sizeof(aa));memset(bb,0,sizeof(bb));mp.clear();}int main() {while(scanf("%d",&n) == 1) {init();for(int i=1;i<=n;i++)scanf("%d",&aa[i]);for(int i=1;i<=n;i++) {mp[aa[i]]++;bb[i] = mp[aa[i]];add(bb[i],1);}mp.clear();ll ans = 0ll;for(int i=n;i>=1;i--) {add(bb[i],-1);mp[aa[i]]++;int tmp = mp[aa[i]];ans += i - get_sum(tmp) - 1;}cout<<ans<<endl;}return 0;}
0 0
- Codeforces Round #261 (Div. 2) D 树状数组应用
- 树状数组Codeforces Round #261 (Div. 2)D
- Codeforces Beta Round #12 (Div 2 Only)D Ball(树状数组的新应用)
- Codeforces Round #220 (Div. 2) D 树状数组 && 二分
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem(树状数组+逆序数对)
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem 离散化+树状数组
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组)
- Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组求逆序数 变形)
- Codeforces Round #285 (Div. 2) D. Misha and Permutations Summation 康托展开 树状数组+二分
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum(离线树状数组)
- Codeforces Round #365 (Div. 2) D Mishka and Interesting sum (离线树状数组)
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum(树状数组)
- Codeforces Round #365 (Div. 2)-D Mishka and Interesting sum(树状数组)
- 【反序表+树状数组】Codeforces Round #441(Div.2)D[Sorting the Coins]题解
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C 离散化+树状数组+map D 数学
- Codeforces Round #248 (Div. 2) B题 【数据结构:树状数组】
- 树状数组Codeforces Round #301 (Div. 2) E - Infinite Inversions
- HDU 3123 GCC(大数阶乘取模)
- java8的函数指针
- 悬浮指针的判断与思考
- SVN源码服务器搭建-详细教程
- cocos2d-x从c++到js】JS与C++的交互1——JS代码调用C++代码
- Codeforces Round #261 (Div. 2) D 树状数组应用
- MySql按日期进行统计(前一天、本周、某一天)
- 【阅读】《如何高效学习》3
- 我的MATLAB学习之路
- cocos2dx 之内存管理
- 【cocos2d-x从c++到js】JS与C++的交互2——JS与C++的“函数重载”问题
- 在main()方法中不能创建非静态内部类的实例
- super的正确用法
- poj 3461 Oulipo kmp