# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
850455 | AliHasanli | XOR Sum (info1cup17_xorsum) | C++17 | 1611 ms | 8292 KiB |
이 제출은 이전 버전의 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;
cin>>n;
int A[n] ;
for(int i=0;i<n;i++)
cin>>A[i];
int ans=xorOfSum(A, n);
for(int i=0;i<n;i++ )
{
ans^=(A[i]*2);
}
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |