Last active
July 11, 2017 15:28
-
-
Save IvanIsCoding/150d7f4b05760c11c631fcdf3c7f34fe to your computer and use it in GitHub Desktop.
Seletiva IOI 2013
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
// 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