2034908d41 2012-05-20 kinaba: #include <iostream> 2034908d41 2012-05-20 kinaba: #include <sstream> 2034908d41 2012-05-20 kinaba: #include <iomanip> 2034908d41 2012-05-20 kinaba: #include <vector> 2034908d41 2012-05-20 kinaba: #include <string> 2034908d41 2012-05-20 kinaba: #include <map> 2034908d41 2012-05-20 kinaba: #include <set> 2034908d41 2012-05-20 kinaba: #include <algorithm> 2034908d41 2012-05-20 kinaba: #include <numeric> 2034908d41 2012-05-20 kinaba: #include <iterator> 2034908d41 2012-05-20 kinaba: #include <functional> 2034908d41 2012-05-20 kinaba: #include <complex> 2034908d41 2012-05-20 kinaba: #include <queue> 2034908d41 2012-05-20 kinaba: #include <stack> 2034908d41 2012-05-20 kinaba: #include <cmath> 2034908d41 2012-05-20 kinaba: #include <cassert> 2034908d41 2012-05-20 kinaba: #include <cstring> 2034908d41 2012-05-20 kinaba: #ifdef __GNUC__ 2034908d41 2012-05-20 kinaba: #include <ext/hash_map> 2034908d41 2012-05-20 kinaba: #define unordered_map __gnu_cxx::hash_map 2034908d41 2012-05-20 kinaba: #else 2034908d41 2012-05-20 kinaba: #include <unordered_map> 2034908d41 2012-05-20 kinaba: #endif 2034908d41 2012-05-20 kinaba: using namespace std; 2034908d41 2012-05-20 kinaba: typedef long long LL; 2034908d41 2012-05-20 kinaba: typedef complex<double> CMP; 2034908d41 2012-05-20 kinaba: 2034908d41 2012-05-20 kinaba: class EllysXors { public: 2034908d41 2012-05-20 kinaba: long long getXor(long long L, long long R) 2034908d41 2012-05-20 kinaba: { 2034908d41 2012-05-20 kinaba: if( R-L < 5 ) { 2034908d41 2012-05-20 kinaba: LL a = 0; 2034908d41 2012-05-20 kinaba: for(LL v=L; v<=R; ++v) 2034908d41 2012-05-20 kinaba: a ^= v; 2034908d41 2012-05-20 kinaba: return a; 2034908d41 2012-05-20 kinaba: } 2034908d41 2012-05-20 kinaba: 2034908d41 2012-05-20 kinaba: LL a = 0; 2034908d41 2012-05-20 kinaba: if( L%2 == 1 ) { 2034908d41 2012-05-20 kinaba: a ^= L; 2034908d41 2012-05-20 kinaba: ++L; 2034908d41 2012-05-20 kinaba: } 2034908d41 2012-05-20 kinaba: if( R%2 == 0 ) { 2034908d41 2012-05-20 kinaba: a ^= R; 2034908d41 2012-05-20 kinaba: --R; 2034908d41 2012-05-20 kinaba: } 2034908d41 2012-05-20 kinaba: return a ^ ((R+1-L)/2%2); 2034908d41 2012-05-20 kinaba: } 2034908d41 2012-05-20 kinaba: }; 2034908d41 2012-05-20 kinaba: 2034908d41 2012-05-20 kinaba: // BEGIN CUT HERE 2034908d41 2012-05-20 kinaba: #include <ctime> 2034908d41 2012-05-20 kinaba: double start_time; string timer() 2034908d41 2012-05-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 2034908d41 2012-05-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 2034908d41 2012-05-20 kinaba: { os << "{ "; 2034908d41 2012-05-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 2034908d41 2012-05-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 2034908d41 2012-05-20 kinaba: void verify_case(const long long& Expected, const long long& Received) { 2034908d41 2012-05-20 kinaba: bool ok = (Expected == Received); 2034908d41 2012-05-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 2034908d41 2012-05-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 2034908d41 2012-05-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 2034908d41 2012-05-20 kinaba: #define END verify_case(_, EllysXors().getXor(L, R));} 2034908d41 2012-05-20 kinaba: int main(){ 2034908d41 2012-05-20 kinaba: 2034908d41 2012-05-20 kinaba: CASE(0) 2034908d41 2012-05-20 kinaba: long long L = 3LL; 2034908d41 2012-05-20 kinaba: long long R = 10LL; 2034908d41 2012-05-20 kinaba: long long _ = 8LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: CASE(1) 2034908d41 2012-05-20 kinaba: long long L = 5LL; 2034908d41 2012-05-20 kinaba: long long R = 5LL; 2034908d41 2012-05-20 kinaba: long long _ = 5LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: CASE(2) 2034908d41 2012-05-20 kinaba: long long L = 13LL; 2034908d41 2012-05-20 kinaba: long long R = 42LL; 2034908d41 2012-05-20 kinaba: long long _ = 39LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: CASE(3) 2034908d41 2012-05-20 kinaba: long long L = 666LL; 2034908d41 2012-05-20 kinaba: long long R = 1337LL; 2034908d41 2012-05-20 kinaba: long long _ = 0LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: CASE(4) 2034908d41 2012-05-20 kinaba: long long L = 1234567LL; 2034908d41 2012-05-20 kinaba: long long R = 89101112LL; 2034908d41 2012-05-20 kinaba: long long _ = 89998783LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: /* 2034908d41 2012-05-20 kinaba: CASE(5) 2034908d41 2012-05-20 kinaba: long long L = LL; 2034908d41 2012-05-20 kinaba: long long R = LL; 2034908d41 2012-05-20 kinaba: long long _ = LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: CASE(6) 2034908d41 2012-05-20 kinaba: long long L = LL; 2034908d41 2012-05-20 kinaba: long long R = LL; 2034908d41 2012-05-20 kinaba: long long _ = LL; 2034908d41 2012-05-20 kinaba: END 2034908d41 2012-05-20 kinaba: */ 2034908d41 2012-05-20 kinaba: } 2034908d41 2012-05-20 kinaba: // END CUT HERE