Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #define MAXN 100010
  4. #define MAXS 1000010
  5. #define max(A,B) (A)>(B)?(A):(B)
  6.  
  7. int MAX = 1000001;
  8. int bit[MAXS];
  9.  
  10. void insere(int x){
  11. while(x < 1000005){
  12. bit[x]++;
  13. x += (x & -x);
  14. }
  15. }
  16.  
  17. int soma_ate(int x){
  18. int s = 0;
  19. while(x > 0){
  20. s += bit[x];
  21. x -= (x & -x);
  22. }
  23. return s;
  24. }
  25.  
  26. int main(){
  27.  
  28. int n;
  29. memset(bit,0,sizeof bit);
  30. scanf("%d",&n);
  31.  
  32. int resp=0;
  33. int hab[MAXN];
  34. int maior=0;
  35. for(int i = 1;i<=n;i++){
  36. scanf("%d",&hab[i]);
  37. maior = max(maior,hab[i]);
  38. }
  39.  
  40. for(int i = 1;i<=n;i++){
  41. insere(hab[i]);
  42. resp += soma_ate(maior) - soma_ate(hab[i]);
  43. }
  44. printf("%d\n",resp);
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement