sacgajcvs

Untitled

Aug 29th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. /*
  2. _____ _ _ _ _
  3. |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
  4. | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  5. | | | | | | __// ___ \| | | \__ \ | | | |_| | |
  6. |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
  7.  
  8. */
  9. #include<bits/stdc++.h>
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12. #define ll long long
  13. #define pb push_back
  14. #define ppb pop_back
  15. #define endl '\n'
  16. #define mii map<ll,ll>
  17. #define msi map<string,ll>
  18. #define mis map<ll, string>
  19. #define rep(i,a,b) for(ll i=a;i<b;i++)
  20. #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
  21. #define trav(a, x) for(auto& a : x)
  22. #define pii pair<ll,ll>
  23. #define vi vector<ll>
  24. #define vii vector<pair<ll, ll>>
  25. #define vs vector<string>
  26. #define all(a) (a).begin(),(a).end()
  27. // #define F first
  28. #define S second
  29. #define sz(x) (ll)x.size()
  30. #define hell 1000000007
  31. #define lbnd lower_bound
  32. #define ubnd upper_bound
  33. #define max(a,b) (a>b?a:b)
  34. #define min(a,b) (a<b?a:b)
  35.  
  36. /* For Debugging */
  37. #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
  38. #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
  39. #define what_is(x) cerr << #x << " is " << x << endl;
  40.  
  41. std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
  42. #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  43. #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  44. #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
  45. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  46. using namespace __gnu_pbds;
  47. using namespace std;
  48. #define PI 3.141592653589793
  49. #define N 100005
  50.  
  51.  
  52. typedef struct item * pitem;
  53. struct item {
  54. int prior, value, cnt, num;
  55. int F;
  56. pitem l, r;
  57. item(int prior,int value,int num) : prior(prior),value(value),num(num),cnt(1),F(num),l(NULL),r(NULL) {};
  58. };
  59.  
  60. void display1(pitem it) {
  61. cout<<"prior: "<<it->prior<<" value: "<<it->value<<" cnt: "<<it->cnt<<" F: "<<it->F<<endl;
  62. }
  63.  
  64. int cnt (pitem it) {
  65. return it ? it->cnt : 0;
  66. }
  67.  
  68. void upd_cnt (pitem it) {
  69. if (it)
  70. it->cnt = cnt(it->l) + cnt(it->r) + 1;
  71. }
  72.  
  73. int find_F (pitem it) {
  74. return it ? it->F : 0;
  75. }
  76.  
  77. void update_F (pitem it) {
  78. if (it) {
  79. it->F = find_F(it->l) + find_F(it->r) + it->num;
  80. }
  81. }
  82.  
  83. void merge (pitem & t, pitem l, pitem r) {
  84. if (!l || !r)
  85. t = l ? l : r;
  86. else if (l->prior > r->prior)
  87. merge (l->r, l->r, r), t = l;
  88. else
  89. merge (r->l, l, r->l), t = r;
  90. upd_cnt (t);
  91. update_F(t);
  92. // display1(t);
  93. }
  94.  
  95. void split (pitem t, pitem & l, pitem & r, int key) {
  96. if (!t)
  97. return void( l = r = 0 );
  98. // int cur_key = add + cnt(t->l);
  99. if (key < t->value)
  100. split (t->l, l, t->l, key), r = t;
  101. else
  102. split (t->r, t->r, r, key), l = t;
  103. upd_cnt (t);
  104. update_F(t);
  105. }
  106.  
  107. void output (pitem t) {
  108. if (!t) return;
  109. output (t->l);
  110. cout<<t->value<<" ";
  111. output (t->r);
  112. }
  113.  
  114. void solve()
  115. {
  116. ll q,sum=0;
  117. cin>>q;
  118. ll a,b;
  119. pitem t=NULL,t1,t2,t3,t4,t5;
  120. rep(i,0,q) {
  121. cin>>a>>b;
  122. // what_is(sum);
  123. // cout<<(a^sum)<<" "<<(b^sum)<<endl;
  124. t1=NULL,t2=NULL,t3=NULL,t4=NULL,t5=NULL;
  125. split(t,t1,t2,(a^sum));
  126. t3 = new item(rand(),(a^sum),(b^sum));
  127. // what_is(t3->F);
  128. // output(t1);
  129. // cout<<endl;
  130. merge(t4,t1,t3);
  131. cout<<(a^sum)<<" "<<t4->F<<endl;
  132. sum=t4->F;
  133. merge(t5,t4,t2);
  134. t = t5;
  135. // output(t);
  136. // cout<<endl;
  137. }
  138. return;
  139. }
  140. int main()
  141. {
  142. #ifndef ONLINE_JUDGE
  143. // freopen ("input.txt","r",stdin);
  144. // freopen("output.txt","w",stdout);
  145. #endif
  146. FAST
  147. int TESTS=1;
  148. // cin>>TESTS;
  149. while(TESTS--)
  150. {
  151. solve();
  152. }
  153. TIME
  154. return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment