hdu-Frosh Week(树状数组)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                hdu-Frosh Week(树状数组)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                求逆序數 ?----》 離散化
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define M 1000005 typedef __int64 LL; LL a[M]; int n; struct node {LL x,y; }s[M]; bool cmp(node p,node q) {return p.x < q.x; } LL lowbit(LL x) {return x&(-x); } void add(LL pos,LL num) {while(pos <= n){a[pos]+=num;pos += lowbit(pos);} } LL getsum(LL pos) {LL res = 0;while(pos > 0){res += a[pos];pos -= lowbit(pos);}return res; } int main() {while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));for(LL i = 1;i <= n;i++){scanf("%I64d",&s[i].x);s[i].y = i;}sort(s+1,s+n+1,cmp);LL ret = 0;for(LL i = 1;i <= n;i++){add(s[i].y,1);ret += i - getsum(s[i].y);}printf("%I64d\n",ret);} }總結
以上是生活随笔為你收集整理的hdu-Frosh Week(树状数组)的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Jeecg-Boot 2.1.4 版本发
 - 下一篇: 微信支付软件架构重构之旅