Artifact Content
Not logged in

Artifact 7b0052037b97ced13a709c7d171574ad3faead1c


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class EllysXors { public:
	long long getXor(long long L, long long R)
	{
		if( R-L < 5 ) {
			LL a = 0;
			for(LL v=L; v<=R; ++v)
				a ^= v;
			return a;
		}

		LL a = 0;
		if( L%2 == 1 ) {
			a ^= L;
			++L;
		}
		if( R%2 == 0 ) {
			a ^= R;
			--R;
		}
		return a ^ ((R+1-L)/2%2);
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, EllysXors().getXor(L, R));}
int main(){

CASE(0)
	long long L = 3LL; 
	long long R = 10LL; 
	long long _ = 8LL; 
END
CASE(1)
	long long L = 5LL; 
	long long R = 5LL; 
	long long _ = 5LL; 
END
CASE(2)
	long long L = 13LL; 
	long long R = 42LL; 
	long long _ = 39LL; 
END
CASE(3)
	long long L = 666LL; 
	long long R = 1337LL; 
	long long _ = 0LL; 
END
CASE(4)
	long long L = 1234567LL; 
	long long R = 89101112LL; 
	long long _ = 89998783LL; 
END
/*
CASE(5)
	long long L = LL; 
	long long R = LL; 
	long long _ = LL; 
END
CASE(6)
	long long L = LL; 
	long long R = LL; 
	long long _ = LL; 
END
*/
}
// END CUT HERE