Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _____ _ _ _ _
- |_ _| |__ ___ / \ _ __ ___| |__ _ _| |
- | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
- | | | | | | __// ___ \| | | \__ \ | | | |_| | |
- |_| |_| |_|\___/_/ \_\_| |_|___/_| |_|\__,_|_|
- */
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define pb push_back
- #define ppb pop_back
- #define endl '\n'
- #define mii map<ll,ll>
- #define msi map<string,ll>
- #define mis map<ll, string>
- #define rep(i,a,b) for(ll i=a;i<b;i++)
- #define repr(i,a,b) for(ll i=b-1;i>=a;i--)
- #define trav(a, x) for(auto& a : x)
- #define pii pair<ll,ll>
- #define vi vector<ll>
- #define vii vector<pair<ll, ll>>
- #define vs vector<string>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll)x.size()
- #define hell 1000000007
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define max(a,b) (a>b?a:b)
- #define min(a,b) (a<b?a:b)
- /* For Debugging */
- #define DEBUG cerr<<"\n>>>I'm Here<<<\n"<<endl;
- #define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
- #define what_is(x) cerr << #x << " is " << x << endl;
- std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
- #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
- #define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
- #define DECIMAL(n) cout << fixed ; cout << setprecision(n);
- #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- using namespace __gnu_pbds;
- using namespace std;
- #define PI 3.141592653589793
- #define N 100005
- #define LOG 60
- ll pw[LOG];
- vi tmp;
- ll fun(ll num,ll p)
- {
- string s="";
- rep(i,0,p)
- {
- s+=(char)((num%4)+'0');
- num/=4;
- }
- // what_is(s);
- s[p-1]=s[p-1]+1;
- ll ans=0;
- repr(i,0,p)
- {
- ans*=4;
- if(s[i]=='0')
- ans+=0;
- else if(s[i]=='1')
- ans+=2;
- else if(s[i]=='2')
- ans+=3;
- else
- ans+=1;
- }
- return ans;
- }
- // ll st2num(string s)
- // {
- // ll num=0,p=1;
- // rep(i,0,s.length())
- // {
- // if(s[i]=='1')
- // num+=p;
- // p*=2;
- // }
- // return num;
- // }
- void solve()
- {
- ll n;
- cin>>n;
- if(n<=3)
- {
- cout<<n<<endl;
- return;
- }
- ll p=lbnd(all(tmp),(n+2)/3)-tmp.begin();
- ll num=(n+2)/3-tmp[p-1]-1;
- // what_is(p);
- ll p1=num+pw[2*p],p2,p3;
- if(n%3==1)
- {
- cout<<num+pw[2*p]<<endl;
- return;
- }
- // cerr<<p1<<" "<<p2<<" "<<p3<<endl;
- // what_is(p);
- // what_is(num);
- // what_is(fun(num));
- ll ans=fun(num,p+1);
- p2=ans;
- p3=(p1^p2);
- if(n%3==2)
- {
- cout<<p2<<endl;
- return;
- }
- cout<<p3<<endl;
- return;
- }
- int main()
- {
- pw[0]=1;
- rep(i,1,LOG)
- {
- pw[i]=pw[i-1]*2;
- }
- for(ll i=0;i<LOG;i+=2)
- tmp.pb(pw[i]);
- rep(i,1,sz(tmp))
- tmp[i]+=tmp[i-1];
- // rep(i,0,sz(tmp))
- // cout<<tmp[i]<<" ";
- // cout<<endl;
- FAST
- int TESTS=1;
- cin>>TESTS;
- while(TESTS--)
- {
- solve();
- }
- TIME
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment