Guest User

Untitled

a guest
Sep 27th, 2020
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
  2. //#pragma GCC target("avx,avx2")
  3. //#pragma GCC target("avx2")
  4. //#pragma GCC optimize("O3")
  5.  
  6. //# include <x86intrin.h>
  7. # include <bits/stdc++.h>
  8.  
  9. # include <ext/pb_ds/assoc_container.hpp>
  10. # include <ext/pb_ds/tree_policy.hpp>
  11.  
  12. using namespace __gnu_pbds;
  13. using namespace std;
  14.  
  15. template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17. #define _USE_MATH_DEFINES_
  18. #define ll long long
  19. #define ld long double
  20. #define Accepted 0
  21. #define pb push_back
  22. #define mp make_pair
  23. #define sz(x) (int)(x.size())
  24. #define every(x) x.begin(),x.end()
  25. #define F first
  26. #define S second
  27. #define lb lower_bound
  28. #define ub upper_bound
  29. #define For(i,x,y) for (ll i = x; i <= y; i ++)
  30. #define FOr(i,x,y) for (ll i = x; i >= y; i --)
  31. #define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  32. // ROAD to... Red
  33.  
  34. void setIn(string s) { freopen(s.c_str(),"r",stdin); }
  35. void setOut(string s) { freopen(s.c_str(),"w",stdout); }
  36. void setIO(string s = "") {
  37. // cin.exceptions(cin.failbit);
  38. // throws exception when do smth illegal
  39. // ex. try to read letter into int
  40. if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
  41. }
  42.  
  43. const double eps = 0.000001;
  44. const ld pi = acos(-1);
  45. const int maxn = 1e7 + 9;
  46. const int mod = 1e9 + 7;
  47. const ll MOD = 1e18 + 9;
  48. const ll INF = 1e18 + 123;
  49. const int inf = 2e9 + 11;
  50. const int mxn = 1e6 + 9;
  51. const int N = 3e5 + 123;
  52. const int M = 22;
  53. const int pri = 997;
  54. const int Magic = 2101;
  55.  
  56. const int dx[] = {-1, 0, 1, 0};
  57. const int dy[] = {0, -1, 0, 1};
  58. mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
  59.  
  60. int rnd (int l, int r) {
  61. return uniform_int_distribution<int> (l, r)(gen);
  62. }
  63.  
  64. int n;
  65. array<int, 2> a[N];
  66.  
  67. ll sum[33][2];
  68.  
  69. vector < int > solve(int bit, int l, int r) {
  70. if (bit < 0 || l == r) {
  71. vector < int > cur(r-l+1);
  72. for (int i = l; i <= r; ++i) {
  73. cur[i-l] = a[i][1];
  74. }
  75.  
  76. return cur;
  77. }
  78.  
  79. int ptr = l;
  80. while(ptr <= r && !(a[ptr][0] & (1<<bit))) {
  81. ++ptr;
  82. }
  83. if(ptr == l || ptr > r) {
  84. return solve(bit-1, l, r);
  85. }
  86. vector < int > A = solve(bit-1, l, ptr-1);
  87. vector < int > B = solve(bit-1, ptr, r);
  88. vector < int > C;
  89. {
  90. int pB = 0;
  91. int nA = sz(A);
  92. int nB = sz(B);
  93.  
  94. ll res = 0;
  95. for (int x : A) {
  96. while(nB > pB && B[pB] < x) {
  97. C.pb(B[pB++]);
  98. }
  99.  
  100. C.pb(x);
  101. res += pB;
  102. }
  103. while(pB < nB) {
  104. C.pb(B[pB++]);
  105. }
  106.  
  107. sum[bit][0] += res;
  108. sum[bit][1] += (nB * (ll)nA) - res;
  109. }
  110.  
  111. return C;
  112. }
  113.  
  114. int main () {
  115. SpeedForce;
  116. cin >> n;
  117. for (int i = 1; i <= n; ++i) {
  118. cin >> a[i][0];
  119. a[i][1] = i;
  120. }
  121.  
  122. sort(a+1, a+n+1);
  123. solve(29, 1, n);
  124. int ans = 0;
  125. ll res = 0;
  126. for (int bit = 0; bit < 30; ++bit) {
  127. int b = (sum[bit][1] < sum[bit][0]);
  128. res += sum[bit][b];
  129. ans += (b<<bit);
  130. }
  131.  
  132. printf("%lld %d\n", res, ans);
  133.  
  134. return Accepted;
  135. }
  136.  
  137. // B...a
RAW Paste Data