#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 < 30; 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;
ans += getsol(n, arr, 1 << bit, 1 << (bit + 1));
ans += getsol(n, arr, (1 << (bit + 1)) + (1 << bit), (1 << (bit + 2)));
}
cout << (ans / 2);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1664 ms |
30224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1664 ms |
30224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |