Submission #1158138

#TimeUsernameProblemLanguageResultExecution timeMemory
1158138yonatanlXOR Sum (info1cup17_xorsum)C++20
45 / 100
1694 ms25684 KiB
#include <iostream> #include <vector> #include <algorithm> #pragma GCC optimize("O3") #define rep(i, s, e) for (ll i = s; i < e; i++) using namespace std; using ll = long long; using vll = vector<ll>; using vb = vector<bool>; void solve() { ll n; cin >> n; vll arr(n); rep(i, 0, n) cin >> arr[i]; ll ans = 0; rep(b, 0, 29) { // Look at the first b bits vll cur0; // Keep all the numbers that have 0 in the b bit with only their first b-1 bits vll cur1; // Keep all the numbers that have 1 in the b bit with only their first b-1 bits ll A = ((ll)1 << (b)) - 1; rep(i, 0, n) { if ((arr[i] >> b) & (ll)1) cur1.push_back(arr[i] & A); else cur0.push_back(arr[i] & A); } sort(cur0.begin(), cur0.end()); sort(cur1.begin(), cur1.end()); ll res = 0; ll carry = (ll)1 << b; rep(i, 0, n) { ll curVal = arr[i] & A; // The first b-1 bits of arr[i] ll num0, num1; if (((2 * arr[i]) >> b) & (ll)1) res++; if (((arr[i] >> b) & (ll)1) == 0) { // The b bit is 0 num0 = 0; // The number of numbers that have 0 in the b bit and give carry num1 = 0; // The number of numbers that have 1 in the b bit and don't give carry num0 = cur0.end() - lower_bound(cur0.begin(), cur0.end(), carry - curVal); num1 = lower_bound(cur1.begin(), cur1.end(), carry - curVal) - cur1.begin(); /*ll f = 0, t = cur0.size() - 1, mid; while (f <= t) { mid = (f + t) / 2; if (cur0[mid] + curVal >= carry) { num0 = cur0.size() - mid; t = mid - 1; } else { f = mid + 1; } } f = 0, t = cur1.size() - 1, mid; while (f <= t) { mid = (f + t) / 2; if (cur1[mid] + curVal < carry) { num1 = mid + 1; f = mid + 1; } else { t = mid - 1; } }*/ } else { // The b bit is 1 num0 = 0; // The number of numbers that have 0 in the b bit and don't give carry num1 = 0; // The number of numbers that have 1 in the b bit and give carry num0 = lower_bound(cur0.begin(), cur0.end(), carry - curVal) - cur0.begin(); num1 = cur1.end() - lower_bound(cur1.begin(), cur1.end(), carry - curVal); /* ll f = 0, t = cur0.size() - 1, mid; while (f <= t) { mid = (f + t) / 2; if (cur0[mid] + curVal >= carry) { num0 = cur0.size() - mid; t = mid - 1; } else { f = mid + 1; } } f = 0, t = cur1.size() - 1, mid; while (f <= t) { mid = (f + t) / 2; if (cur1[mid] + curVal < carry) { num1 = mid + 1; f = mid + 1; } else { t = mid - 1; } }*/ } res += (num0 + num1); } res /= 2; ans += (res % 2) * carry; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...