标签:man stdio.h sizeof oid exp bsp family class iostream
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <list> #include <algorithm> #include <climits> using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 67000 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) const int mod = 1e9+7; LL c[N],n,tot,r[N]; struct node { LL x,s,id; } a[N]; int cmp(node a,node b) { if(a.x!=b.x) return a.x<b.x; return a.id<b.id; } LL sum(LL x) { LL ret = 0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret; } void add(LL x,LL d) { while(x<=n) { c[x]+=d; x+=lowbit(x); } } int main() { LL i,j,k; while(~scanf("%lld",&n)) { MEM(c,0); for(i = 1; i<=n; i++) { scanf("%lld",&a[i].x); a[i].id = i; } sort(a+1,a+1+n,cmp); for(i = 1; i<=n; i++) { r[a[i].id] = i; } LL ans = 0; for(i = 1; i<=n; i++) { add(r[i],1); ans+=(i-sum(r[i])); } printf("%lld\n",ans); } return 0; }
标签:man stdio.h sizeof oid exp bsp family class iostream
原文地址:http://www.cnblogs.com/claireyuancy/p/7241707.html