sacgajcvs

Untitled

Apr 12th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 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. #define LOG 60
  51. ll pw[LOG];
  52. vi tmp;
  53.  
  54.  
  55. ll fun(ll num,ll p)
  56. {
  57. string s="";
  58. rep(i,0,p)
  59. {
  60. s+=(char)((num%4)+'0');
  61. num/=4;
  62. }
  63. // what_is(s);
  64. s[p-1]=s[p-1]+1;
  65. ll ans=0;
  66. repr(i,0,p)
  67. {
  68. ans*=4;
  69. if(s[i]=='0')
  70. ans+=0;
  71. else if(s[i]=='1')
  72. ans+=2;
  73. else if(s[i]=='2')
  74. ans+=3;
  75. else
  76. ans+=1;
  77. }
  78. return ans;
  79. }
  80.  
  81. // ll st2num(string s)
  82. // {
  83. // ll num=0,p=1;
  84.  
  85. // rep(i,0,s.length())
  86. // {
  87. // if(s[i]=='1')
  88. // num+=p;
  89. // p*=2;
  90. // }
  91. // return num;
  92. // }
  93. void solve()
  94. {
  95. ll n;
  96. cin>>n;
  97. if(n<=3)
  98. {
  99. cout<<n<<endl;
  100. return;
  101. }
  102. ll p=lbnd(all(tmp),(n+2)/3)-tmp.begin();
  103. ll num=(n+2)/3-tmp[p-1]-1;
  104. // what_is(p);
  105. ll p1=num+pw[2*p],p2,p3;
  106. if(n%3==1)
  107. {
  108. cout<<num+pw[2*p]<<endl;
  109. return;
  110. }
  111. // cerr<<p1<<" "<<p2<<" "<<p3<<endl;
  112. // what_is(p);
  113. // what_is(num);
  114. // what_is(fun(num));
  115. ll ans=fun(num,p+1);
  116. p2=ans;
  117. p3=(p1^p2);
  118. if(n%3==2)
  119. {
  120. cout<<p2<<endl;
  121. return;
  122. }
  123. cout<<p3<<endl;
  124. return;
  125. }
  126. int main()
  127. {
  128. pw[0]=1;
  129. rep(i,1,LOG)
  130. {
  131. pw[i]=pw[i-1]*2;
  132. }
  133. for(ll i=0;i<LOG;i+=2)
  134. tmp.pb(pw[i]);
  135. rep(i,1,sz(tmp))
  136. tmp[i]+=tmp[i-1];
  137.  
  138. // rep(i,0,sz(tmp))
  139. // cout<<tmp[i]<<" ";
  140. // cout<<endl;
  141.  
  142. FAST
  143. int TESTS=1;
  144. cin>>TESTS;
  145. while(TESTS--)
  146. {
  147. solve();
  148. }
  149. TIME
  150. return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment