이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// Function to find XOR of pairwise
// sum of every unordered pairs
int xorOfSum(int a[], int n)
{
int i, j, k;
// Sort the array
sort(a, a + n);
int ans = 0;
// Array elements are not greater
// than 1e7 so 27 bits are suffice
for (k = 0; k < 27; ++k) {
// Modded elements of array
vector<int> b(n);
// Loop to find the modded
// elements of array
for (i = 0; i < n; i++)
b[i] = a[i] % (1 << (k + 1));
// Sort the modded array
sort(b.begin(), b.end());
int cnt = 0;
for (i = 0; i < n; i++) {
// finding the bound for j
// for given i using binary search
int l = lower_bound(b.begin() +
i + 1, b.end(),
(1 << k) - b[i]) - b.begin();
int r = lower_bound(b.begin() +
i + 1, b.end(), (1 << (k + 1)) -
b[i]) - b.begin();
// All the numbers in the range
// of indices can be added to the
// count to check the xor.
cnt += r - l;
l = lower_bound(b.begin() + i + 1,
b.end(), (1 << (k + 1)) +
(1 << k) - b[i]) - b.begin();
cnt += n - l;
}
// Remainder of cnt * kth power
// of 2 added to the xor value
ans += (cnt % 2) * 1LL * (1 << k);
}
return ans;
}
// Driver Code
int main()
{
int n = 3;
int A[n] = { 1, 2, 3 };
cout << xorOfSum(A, n);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In function 'int xorOfSum(int*, int)':
xorsum.cpp:10:12: warning: unused variable 'j' [-Wunused-variable]
10 | int i, j, k;
| ^| # | 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... |