이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define N 1000005
#define LOGN 20
#define int long long
int arr[N];
int32_t main()
{
//fileio();
fastio();
int n;
cin>>n;
int maks = 0;
for (int i = 1; i <= n; i++)
{
cin>>arr[i];
maks = max(maks, arr[i]);
}
int ans = 0;
for (int i = 0; ((int)1<<(i - 1)) <= maks ; i++)
{
//cout<<ans<<endl;
int m = (int)1<<(i + 1);
int k = (1<<i);
vector<int> cnt(m, 0);
vector<int> v(m + 5, 0);
for (int j = 1; j <= n; j++)
cnt[arr[j] % m]++;
for (int j = 1; j <= m; j++)
v[j] = v[j - 1] + cnt[j - 1];
/*
for (auto j : v) cout<<j<<sp;
cout<<endl;
*/
int sum = 0, tmp = 0;
for (int j = 1; j <= n; j++)
{
int l = ((k - arr[j]) % m + m) % m;
int r = m - 1 - (arr[j] % m);
int curr = arr[j] % m;
//cout<<curr<<sp<<l<<sp<<r<<sp;
if (l <= r)
{
sum += v[r + 1] - v[l];
//if (cnt[l]) sum++;
if (curr >= l && curr <= r) sum++;
}
else
{
sum += n - (v[l] - v[r + 1]);
//if (cnt[r + 1]) sum--;
if (curr >= l || curr <= r) sum++;
}
//cout<<sum<<endl;
}
//cout<<sum<<endl;
sum /= 2;
ans += (sum % 2) * k;
}
cout<<ans<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In function 'int32_t main()':
xorsum.cpp:46:16: warning: unused variable 'tmp' [-Wunused-variable]
46 | int sum = 0, tmp = 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... |