Precreation contest files
This commit is contained in:
37
misc/mysterious/tgc.cpp
Normal file
37
misc/mysterious/tgc.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int a[500000];
|
||||
|
||||
int main() {
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
freopen("tgc.inp", "r", stdin);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> a[i];
|
||||
sort(a, a + n);
|
||||
|
||||
int res = 0;
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
if (a[i] != a[i + 1])
|
||||
continue;
|
||||
|
||||
int l = i, r = n - 1;
|
||||
int mid;
|
||||
while (l < r) {
|
||||
mid = (l + r) / 2;
|
||||
|
||||
if (a[mid] < 2 * a[i]) {
|
||||
l = mid + 1;
|
||||
} else {
|
||||
r = mid;
|
||||
}
|
||||
}
|
||||
res += r - mid + l;
|
||||
}
|
||||
cout << res << "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user