# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
886504 | AnhPham | XOR Sum (info1cup17_xorsum) | C++17 | 2 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef OP_DEBUG
#include <algo/debug.h>
#else
#define debug(...) 26
#endif
using namespace std;
#define int long long // maybe tle?
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define TcT template <class T
const int MOD = (int)1e9 + 7, INF = (int)2e9 + 9, INF64 = (int)4e18 + 18;
TcT> bool minimize(T &lhs, const T &rhs) { return rhs < lhs ? lhs = rhs, 1 : 0; }
TcT> bool maximize(T &lhs, const T &rhs) { return rhs > lhs ? lhs = rhs, 1 : 0; }
TcT, class S> istream &operator >> (istream &scanf, pair <T, S> &u) { return scanf >> u.first >> u.second; }
TcT, class S> ostream &operator << (ostream &print, pair <T, S> &u) { return print << u.first << ' ' << u.second; }
void solve();
int32_t main() {
freopen("input.inp", "r", stdin);
freopen("B.out", "w", stdout);
cin.tie(nullptr), cout.tie(nullptr) -> sync_with_stdio(0);
int testcases = 1;
#define TC 0
if (TC) { cin >> testcases; } for (; testcases--;) { solve(); }
}
/* [Pham Hung Anh - 11I - Tran Hung Dao High School for Gifted Student] */
const int N = 3e5 + 5;
int n;
int a[N];
int check(int bit) {
int cnt = 0;
vector <int> rems;
for (int i = 1; i <= n; ++i) {
if ((a[i] & (1 << bit)))
++cnt;
rems.push_back(a[i] % (1 << bit));
}
sort(all(rems));
int ans = cnt * (n - cnt) % 2;
int r = n - 1;
for (int l = 0; l < n; ++l) {
if (l > r)
++r;
while (r > l && rems[l] + rems[r - 1] >= (1 << bit))
--r;
if (rems[l] + rems[r] >= (1 << bit))
ans = (ans + n - r) % 2;
}
return ans;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
int ans = 0;
for (int i = 0; i <= 29; ++i)
if (check(i))
ans |= (1 << i);
cout << ans << '\n';
}
컴파일 시 표준 에러 (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... |