Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 100005
- using namespace std;
- int aib[N],n;
- void Add(int x)
- {
- while(x<=n)
- {
- ++aib[x];
- x+=(x&(-x));
- }
- }
- int Sol(int x)
- {
- int s=0;
- while(x>=1)
- {
- s+=aib[x];
- x-=(x&(-x));
- }
- return s;
- }
- int main()
- {
- int x;
- cin>>n;
- for(int i=1;i<=n;i++)
- {
- cin>>x;
- cout<<Sol(x-1)<<' ';
- Add(x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement