前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU 6318 树状数组求逆序数

HDU 6318 树状数组求逆序数

作者头像
用户2965768
发布2018-08-30 15:39:46
4020
发布2018-08-30 15:39:46
举报
文章被收录于专栏:wymwym

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6318

#define N 100005 #include <bits/stdc++.h> using namespace std; int c[N];  int n; int lowbit(int i) {     return i&(-i); } int insert(int i,int x) {     while(i<=n){         c[i]+=x;         i+=lowbit(i);     }     return 0; }

int getsum(int i) {     int sum=0;     while(i>0){         sum+=c[i];         i-=lowbit(i);     }      return sum; } void output() {     for(int i=1;i<=n;i++) cout<<c[i]<<" ";     cout<<endl; } struct node{     int v;     int id;     bool operator <(const node &b)const{     if(v==b.v)      return id<b.id;      else return v<b.v;     } }; node a[N]; int main() {     int x,y;     while(~scanf("%d %d %d",&n,&x,&y)){         long long ans=0;         memset(c,0,sizeof(c));         for(int i=1;i<=n;i++){             scanf("%d",&a[i].v);             a[i].id=i;         }         sort(a+1,a+1+n);         for(int i=1;i<=n;i++)             {             insert(a[i].id,1);             ans+=i-getsum(a[i].id);//统计当前序列中大于a的元素的个数          }         cout<<ans*min(x,y)<<endl;     }     return 0; }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年07月26日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档