Submission #720355

# Submission time Handle Problem Language Result Execution time Memory
720355 2023-04-08T04:55:32 Z GrandTiger1729 XOR Sum (info1cup17_xorsum) C++17
0 / 100
1241 ms 39020 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 30;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    if (n % 2 == 0){
        for (int j = 0; j < N; j++){
            int cnt = 0;
            for (int i = 0; i < n; i++){
                if (a[i] & 1 << j)
                    cnt++;
            }
            ans ^= (cnt & 1) << j;
        }
    }
    vector<pair<int, int>> res(n);
    for (int i = 0; i < n; i++)
        res[i] = make_pair(a[i] & 1, i);
    sort(res.begin(), res.end());
    auto calc = [&](int j) -> long long {
        int r = n;
        long long ret = 0;
        // for (int i = 0; i < n; i++){
        //     while (r > 0 && res[r - 1].first >= (1 << j) - res[i].first) r--;
        //     ret += n - r;
        //     ret += res[i].first >= (1 << j - 1);
        // }
        for (int i = 0; i < n; i++){
            ret += res.end() - lower_bound(res.begin(), res.end(), make_pair((1 << j) - res[i].first, -1));
            ret += res[i].first >= (1 << j - 1);
        }
        return ret;
    };
    long long cnt = calc(1) / 2;
    ans ^= (cnt & 1) << 1;
    for (int j = 2; j <= N; j++){
        vector<pair<int, int>> b, c;
        for (int i = 0; i < n; i++){
            if (a[res[i].second] & 1 << j)
                c.push_back(make_pair(res[i].first ^ 1 << j, res[i].second));
            else
                b.push_back(res[i]);
        }
        b.insert(b.end(), c.begin(), c.end());
        swap(res, b);
        cnt = calc(j) / 2;
        ans ^= (cnt & 1) << j;
    }
    cout << ans << '\n';
    return 0;
}

Compilation message

xorsum.cpp: In lambda function:
xorsum.cpp:36:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   36 |             ret += res[i].first >= (1 << j - 1);
      |                                          ~~^~~
xorsum.cpp:27:13: warning: unused variable 'r' [-Wunused-variable]
   27 |         int r = n;
      |             ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1241 ms 39020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1241 ms 39020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -