Skip to content

Instantly share code, notes, and snippets.

@IvanIsCoding
Last active July 11, 2017 15:28
Show Gist options
  • Save IvanIsCoding/150d7f4b05760c11c631fcdf3c7f34fe to your computer and use it in GitHub Desktop.
Save IvanIsCoding/150d7f4b05760c11c631fcdf3c7f34fe to your computer and use it in GitHub Desktop.
Seletiva IOI 2013
// Ivan Carvalho
// Código - Seletiva IOI - OBI 2013
#include <bits/stdc++.h>
#define MAXN 100010
#define LSOne(S) (S & (-S))
int bit[MAXN];
void update(int ind){
while(ind < MAXN){
bit[ind]++;
ind += LSOne(ind);
}
}
int sum(int ind){
int answer = 0;
while(ind > 0){
answer += bit[ind];
ind -= LSOne(ind);
}
return answer;
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int davez;
scanf("%d",&davez);
update(davez);
printf("%d ",sum(n)-sum(davez));
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment