DSA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4 KiB

  1. /*
  2. #pragma GCC target ("avx2")
  3. #pragma GCC optimize ("Ofast")
  4. #pragma GCC optimize ("unroll-loops")
  5. */
  6. #include "bits/stdc++.h"
  7. #define iosb ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  8. #define BIT(x) __builtin_popcount(x)
  9. #define all(x) x.begin() , x.end()
  10. #define F first
  11. #define S second
  12. #define pb push_back
  13. using namespace std ;
  14. typedef unsigned long long UL ;
  15. typedef long long L ;
  16. typedef string T ;
  17. typedef int I ;
  18. const I MaxN = 1e5+1 ;
  19. const I MOD = 1e9+7 ;
  20. const I inf = 2e9+7 ;
  21. const L INF = 2e18+7 ;
  22. L t[4*MaxN], mod[4*MaxN], a[MaxN], n, m ;
  23. void update(int v, int tl, int tr, int l, int x)
  24. {
  25. if(tl == tr && tl == l)
  26. {
  27. t[v] = x ;
  28. return ;
  29. }
  30. if(tr < l || l < tl)
  31. return ;
  32. int tm = (tl + tr) >> 1 ;
  33. update(v*2, tl, tm, l, x) ;
  34. update(v*2+1, tm+1, tr, l, x) ;
  35. t[v] = t[v*2] + t[v*2+1] ;
  36. }
  37. L get(int v, int tl, int tr, int l, int r)
  38. {
  39. if(l <= tl && tr <= r)
  40. return t[v] ;
  41. if(l > tr || r < tl)
  42. return 0 ;
  43. int tm = (tl + tr) >> 1 ;
  44. return get(v*2, tl, tm, l, r) + get(v*2+1, tm+1, tr, l, r) ;
  45. }
  46. int32_t main(int argc, char *argv[])
  47. {
  48. if(argc > 1)
  49. freopen(argv[1], "r", stdin) ;
  50. //freopen(".in" , "r" , stdin) ;
  51. //freopen(".out" , "w" , stdout) ;
  52. cin >> n ;
  53. for(int i = 0 ; i < n ; ++i)
  54. {
  55. cin >> a[i] ;
  56. cout << get(1, 1, n, a[i], n) << ' ' ;
  57. update(1, 1, n, a[i], 1) ;
  58. }
  59. }