Advertisement
nicuvlad76

Untitled

Nov 24th, 2020
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 100005
  3. using namespace std;
  4.  
  5. int aib[N],n;
  6.  
  7. void Add(int x)
  8. {
  9.     while(x<=n)
  10.     {
  11.         ++aib[x];
  12.         x+=(x&(-x));
  13.     }
  14. }
  15. int Sol(int x)
  16. {
  17.     int s=0;
  18.     while(x>=1)
  19.     {
  20.         s+=aib[x];
  21.         x-=(x&(-x));
  22.     }
  23.     return s;
  24. }
  25. int main()
  26. {
  27.     int x;
  28.     cin>>n;
  29.     for(int i=1;i<=n;i++)
  30.     {
  31.         cin>>x;
  32.         cout<<Sol(x-1)<<' ';
  33.         Add(x);
  34.     }
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement