fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<int>getCount(int n,int arr[]){
  4. vector<int>pre(n+1,0);
  5. for(int i=1;i<n;i++){
  6. int count=0;
  7. for(int j=0;j<=i-1;j++){ //as i<k
  8. if(arr[j]>arr[i]){
  9. count++;
  10. }
  11. }
  12. pre[i]=count;
  13. }
  14. return pre;
  15. }
  16.  
  17. int main() {
  18. // your code goes here
  19. int n;
  20. cin>>n;
  21. int arr[n];
  22. for(int i=0;i<n;i++){
  23. cin>>arr[i];
  24. }
  25. vector<int>newArr=getCount(n,arr);
  26. for(int i=0;i<n;i++){
  27. cout<<newArr[i];
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5284KB
stdin
6
8 1 2 3 4 5 
stdout
011111