Submission #97196

#TimeUsernameProblemLanguageResultExecution timeMemory
97196caesar2001XOR Sum (info1cup17_xorsum)C++14
100 / 100
1568 ms35704 KiB
#include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <cmath> #include <utility> using namespace std; typedef long long ll; ll getsol(int n, const vector<pair<int, int>> &v, int l, int r) { int i = n, k = n; ll ans = 0; for(int j = 1; j <= n; j ++) { while(i >= 1 && l - v[j].first <= v[i].first) i --; while(k >= 1 && r - v[j].first <= v[k].first) k --; if(k >= 1 && v[k].first < r - v[j].first) ans += (k - i); } return ans; } int main() { //freopen("a.in", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v(n + 1, 0); for(int i = 1; i <= n; i ++) cin >> v[i]; vector<pair<int, int>> arr(n + 1, {0, 0}); for(int i = 1; i <= n; i ++) arr[i].second = i; ll ans = 0; vector<vector<pair<int, int>>> sorted(2, vector<pair<int, int>> (n + 1)); for(int bit = 0; bit <= 29; bit ++) { vector<int> sz(2, 0); for(int i = 1; i <= n; i ++) sorted[(v[arr[i].second] & (1 << bit)) == (1 << bit)][sz[(v[arr[i].second] & (1 << bit)) == (1 << bit)] ++] = {arr[i].first + (v[arr[i].second] & (1 << bit)), arr[i].second}; int pos = 0; for(int i = 0; i < sz[0]; i ++) arr[++ pos] = sorted[0][i]; for(int i = 0; i < sz[1]; i ++) arr[++ pos] = sorted[1][i]; ll aux = getsol(n, arr, 1 << bit, 1 << (bit + 1)) + getsol(n, arr, (1 << (bit + 1)) + (1 << bit), (1 << (bit + 2))); for(int i = 1; i <= n; i ++) if((2 * v[i]) & (1 << bit)) aux ++; aux /= 2; if(aux % 2 == 1) ans += (1 << bit); } cout << ans; return 0; }
#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...