Artifact ca93294461342c9b7ef4553e91413e8e49e16e6e
#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 <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const unsigned MODVAL = 1000000007;
class XorOrderDiv1 { public:
int get(int m, int n, int a0, int b)
{
vector<int> a;
for(int i=0; i<n; ++i)
a.push_back(int((a0 + LL(i)*b) % (1LL<<m)));
sort(a.begin(), a.end());
return solve(a, m);
}
int solve(const vector<int>& A, int M)
{
vector<int> d;
return solve_rec(A, 0, A.size(), M-1, d);
}
int solve_rec(const vector<int>& A, int s, int e, int bit, vector<int>& d)
{
if(s==e)
return 0;
if(bit == -1) {
const int M = d.size();
LL q = 0;
LL sigma = 0;
for(int m=M-1; m>=0; --m)
{
LL qprev = q;
LL dd = d[m];
q = dd*dd%MODVAL*(1LL<<(M-m-1)) + sigma*dd%MODVAL*(1LL<<(M-m-1)) + 2*qprev;
sigma += dd;
}
return int(q % MODVAL);
}
int m=s;
for(; m<e; ++m)
if(A[m]&(1<<bit))
break;
int ans = 0;
d.push_back(e-m);
ans ^= solve_rec(A, s, m, bit-1, d);
d.pop_back();
d.push_back(m-s);
ans ^= solve_rec(A, m, e, bit-1, d);
d.pop_back();
return ans;
}
};
// 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 int& Expected, const int& 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(_, XorOrderDiv1().get(m, n, a0, b));}
int main(){
CASE(0)
int m = 2;
int n = 3;
int a0 = 0;
int b = 1;
int _ = 8;
END
CASE(1)
int m = 3;
int n = 5;
int a0 = 1;
int b = 3;
int _ = 48;
END
CASE(2)
int m = 16;
int n = 100;
int a0 = 41;
int b = 5;
int _ = 523436032;
END
CASE(3)
int m = 30;
int n = 200000;
int a0 = 399;
int b = 18082016;
int _ = 408585698;
END
/*
CASE(4)
int m = ;
int n = ;
int a0 = ;
int b = ;
int _ = ;
END
CASE(5)
int m = ;
int n = ;
int a0 = ;
int b = ;
int _ = ;
END
*/
}
// END CUT HERE