Created
April 13, 2015 03:58
-
-
Save luccasiau/23016d5534d7b788163a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#define MAXN 100010 | |
#define MAXS 1000010 | |
#define max(A,B) (A)>(B)?(A):(B) | |
int MAX = 1000001; | |
int bit[MAXS]; | |
void insere(int x){ | |
while(x < 1000005){ | |
bit[x]++; | |
x += (x & -x); | |
} | |
} | |
int soma_ate(int x){ | |
int s = 0; | |
while(x > 0){ | |
s += bit[x]; | |
x -= (x & -x); | |
} | |
return s; | |
} | |
int main(){ | |
int n; | |
memset(bit,0,sizeof bit); | |
scanf("%d",&n); | |
int resp=0; | |
int hab[MAXN]; | |
int maior=0; | |
for(int i = 1;i<=n;i++){ | |
scanf("%d",&hab[i]); | |
maior = max(maior,hab[i]); | |
} | |
for(int i = 1;i<=n;i++){ | |
insere(hab[i]); | |
resp += soma_ate(maior) - soma_ate(hab[i]); | |
} | |
printf("%d\n",resp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment