PAT T1010 Lehmer Code
跟1009几乎是同一道题~
#include<bits/stdc++.h> using namespace std; const int maxn=1e6+14; int a[maxn]; int c[maxn*8]; int r[maxn]; int lowbit (int x) { return x&-x; } int main () { int N; scanf ("%d",&N); for (int i=0;i<N;i++) { scanf ("%d",&a[i]); a[i]+=10010; } for (int i=N-1;i>=0;i--) { for (int j=a[i]-1;j>0;j-=lowbit(j)) r[i]+=c[j]; for (int j=a[i];j<maxn;j+=lowbit(j)) c[j]++; } for (int i=0;i<N;i++) { if (i!=0) printf (" "); printf ("%d",r[i]); } return 0; }