Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement