This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<string>
#include<assert.h>
#include<math.h>
#include<chrono>
#include<random>
#include<bitset>
using namespace std;
const int64_t INF = (int64_t) 1e9 + 5;
const int64_t mINF = (int64_t) 2 * 1e6 + 5;
const int64_t MOD = (int64_t) 1e9 + 19972207;
const int nbit = 30;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up
struct Solution
{
int n;
vector<int> a;
Solution() {}
void solve()
{
cin >> n;
a.resize(n);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
int ans = 0;
sort(a.begin(), a.end());
for(int b = nbit; b >= 0; b--)
{
Sort(b);
int j = n;
int k = n;
int l = n;
int cnt = 0;
for(int i = 0; i < n; i++)
{
j = max(j, i);
k = max(k, i);
l = max(l, i);
while(i < j && a[i] + a[j - 1] >= MASK(b)) j--;
while(i < k && a[i] + a[k - 1] > MASK(b + 1) - 1) k--;
while(i < l && a[i] + a[l - 1] >= MASK(b + 1) + MASK(b)) l--;
cnt += k - j;
cnt += n - l;
}
if(cnt % 2 != 0) ans |= MASK(b);
}
cout << ans << "\n";
}
void Sort(int b)
{
vector<int> tmp = a;
int x = n;
for(int i = 0; i < n; i++)
{
if(tmp[i] >= MASK(b + 1))
{
tmp[i] %= MASK(b + 1);
x = min(x, i);
}
}
int id = 0;
int l = 0;
int r = x;
while(l < x && r < n)
{
if(tmp[l] < tmp[r]) a[id] = tmp[l++];
else a[id] = tmp[r++];
id++;
}
while(l < x)
{
a[id] = tmp[l++];
id++;
}
while(r < n)
{
a[id] = tmp[r++];
id++;
}
}
int modsub(int t1, int t2)
{
int64_t res = t1 - t2;
if(res < 0) res += MOD;
return res;
}
int modadd(int t1, int t2)
{
int64_t res = t1 + t2;
if(res >= MOD) res -= MOD;
return res;
}
int modmul(int t1, int t2)
{
int64_t res = 1LL * t1 * t2;
return (res % MOD);
}
bool BIT(int mask, int j)
{
return (mask & MASK(j));
}
int MASK(int j)
{
return (1 << j);
}
int64_t Abs(int64_t t1)
{
if(t1 < 0) return -t1;
return t1;
}
};
void __startup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
int main()
{
__startup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |