-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathD.cpp
163 lines (127 loc) · 3.22 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <bits/stdc++.h>
using namespace std;
#define int long long
// Z_P (Modular Arithmetic) {{{
template <unsigned P>
struct Z {
unsigned value;
constexpr Z() : value(0) {}
template<typename T, typename = enable_if_t<std::is_integral<T>::value>>
constexpr Z(T a) : value((((long long)a % P) + P) % P) {}
Z& operator+=(Z rhs) {
value += rhs.value;
if (value >= P) value -= P;
return *this;
}
Z& operator-=(Z rhs) {
value += P - rhs.value;
if (value >= P) value -= P;
return *this;
}
Z& operator*=(Z rhs) {
value = (unsigned long long)value * rhs.value % P;
return *this;
}
Z& operator/=(Z rhs) { return *this *= pow(rhs, -1); }
Z operator+() const { return *this; }
Z operator-() const { return Z() - *this; }
bool operator==(Z rhs) const { return value == rhs.value; }
bool operator!=(Z rhs) const { return value != rhs.value; }
friend Z operator+(Z lhs, Z rhs) { return lhs += rhs; }
friend Z operator-(Z lhs, Z rhs) { return lhs -= rhs; }
friend Z operator*(Z lhs, Z rhs) { return lhs *= rhs; }
friend Z operator/(Z lhs, Z rhs) { return lhs /= rhs; }
friend ostream& operator<<(ostream& out, Z a) { return out << a.value; }
friend istream& operator>>(istream& in, Z& a) {
long long x;
in >> x;
a = Z(x);
return in;
}
};
template<unsigned P>
Z<P> pow(Z<P> x, long long p) {
if (x == 0) {
return p == 0 ? 1 : 0;
}
p %= P -1;
if (p < 0) p += P-1;
Z<P> res = 1;
while (p) {
if (p & 1) {
res *= x;
}
x *= x;
p >>= 1;
}
return res;
}
//}}}
const int MOD = 1e9+7;
using mint = Z<MOD>;
const int MAXA = 1e6;
// Debug {{{
#define var(x) "[", #x, " ", x, "] "
template<typename ...A> void db(A const&... a) { ((cout << (a)), ...); cout << endl; }
//}}}
const vector P10{1, 10, 100, 1'000, 10'000, 100'000, 1'000'000};
template<typename T>
void sos(vector<T> &A) {
for (int d = 0; d < 6; d++) {
for (int i = 0; i < 1e6; i++) {
int dig = (i/P10[d])%10;
for (int j = 1; j <= dig; j++) {
int ni = i - j*P10[d];
A[ni] += A[i];
}
}
}
}
template<typename T>
void sos_minus(vector<T> &A) {
for (int d = 0; d < 6; d++) {
for (int i = 1e6-1; i >= 0; i--) {
int dig = (i/P10[d])%10;
for (int j = 1; j < 10-dig; j++) {
int ni = i + j*P10[d];
A[i] -= A[ni];
}
}
}
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N;
cin >> N;
vector<int> cnt(MAXA);
vector<mint> ssq(MAXA), sum(MAXA);
for (int i = 0; i < N; i++) {
int x;
cin >> x;
cnt[x] += 1;
ssq[x] += x*x;
sum[x] += x;
}
sos(cnt);
sos(sum);
sos(ssq);
vector<mint> GS(MAXA);
for (int i = 0; i < 1e6; i++) {
if (cnt[i] == 0) continue;
GS[i] = pow(mint(2), cnt[i]-2) * (sum[i] * sum[i] + ssq[i]);
}
sos_minus(GS);
long long ans = 0;
for (int i = 0; i < 1e6; i++) {
auto g = GS[i];
ans ^= (long long)i * g.value;
}
cout << ans << endl;
}
/* Solution Notes {{{
GS[s] =
x y z w
8x^2 + 8xy + 8xz + 8xw
(x+y+z+w)^2
x^2 + 2xy + 2xz + 2yz
}}} */