Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <vector>
- #include <cstdint>
- #include <cassert>
- #include <algorithm>
- int solve_slow(const std::vector<uint32_t>& a) {
- const int n = (int)a.size();
- uint32_t s = 0; for (auto it : a) s ^= it;
- for (int i = 0; i < n-1; ++i) {
- uint32_t b = 0;
- for (int j = i + 1; j < n; ++j) {
- uint32_t diff = a[j] - a[i];
- b ^= (diff | (diff - 1)) - diff;
- }
- s ^= b;
- }
- return (int)s;
- }
- int main() {
- freopen("input.txt", "rt", stdin);
- int n;
- scanf("%d", &n);
- std::vector<uint32_t> a(n);
- for (auto& it : a) {
- int value; scanf("%d", &value);
- it = (uint32_t)value;
- }
- std::sort(a.begin(), a.end());
- printf("%d", solve_slow(a));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement