#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;
for(int bit = 0; bit <= 29; bit ++) {
vector<vector<pair<int, int>>> sorted(2);
for(int i = 1; i <= n; i ++)
sorted[(v[arr[i].second] & (1 << bit)) == (1 << bit)].push_back({arr[i].first + (v[arr[i].second] & (1 << bit)), arr[i].second});
int pos = 0;
for(auto it : sorted[0])
arr[++ pos] = it;
for(auto it : sorted[1])
arr[++ pos] = it;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1608 ms |
30012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1608 ms |
30012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
132 ms |
3460 KB |
Output is correct |
4 |
Correct |
148 ms |
3508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Execution timed out |
1608 ms |
30012 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |