#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cerr << #x << ": " << x << endl;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m;
cin >> m;
int n = 1 << m;
int max_mask = n - 1;
vector<int> s(n);
vector<uint64_t> xor_hash(n);
mt19937_64 rng(1233);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x & (1 << (m - 1))) x ^= max_mask;
s[i] = x;
xor_hash[i] = rng();
}
long long ans = 1LL * n * (n + 1) / 2 - (m == 1);
vector<unordered_map<uint64_t, int>> pos(4);
++pos[3][0];
uint64_t pref = 0;
for (int i = 0; i < n; ++i) {
pref ^= xor_hash[s[i]];
ans -= pos[i % 4][pref];
++pos[i % 4][pref];
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1108 KB |
Output is correct |
2 |
Correct |
4 ms |
840 KB |
Output is correct |
3 |
Correct |
4 ms |
976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3772 KB |
Output is correct |
2 |
Correct |
16 ms |
3044 KB |
Output is correct |
3 |
Correct |
35 ms |
5872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3788 KB |
Output is correct |
2 |
Correct |
30 ms |
5832 KB |
Output is correct |
3 |
Correct |
90 ms |
13076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
14232 KB |
Output is correct |
2 |
Correct |
73 ms |
11464 KB |
Output is correct |
3 |
Correct |
71 ms |
11696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
692 ms |
56696 KB |
Output is correct |
2 |
Correct |
663 ms |
56444 KB |
Output is correct |
3 |
Correct |
286 ms |
34472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
674 ms |
56492 KB |
Output is correct |
2 |
Correct |
479 ms |
45544 KB |
Output is correct |
3 |
Correct |
561 ms |
48436 KB |
Output is correct |
4 |
Correct |
661 ms |
56480 KB |
Output is correct |