fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25.  
  26. int consistency(int n){
  27.  
  28. vector<int> b;
  29. unordered_set<int> st;
  30. for(int i=0; i<n; i++){
  31. if(!st.count(a[i])){
  32. b.push_back(abs(a[i]));
  33. }
  34. st.insert(a[i]);
  35. }
  36. sort(begin(b), end(b));
  37.  
  38. int m = b.size();
  39.  
  40. int ans = 0;
  41. for(int i=0; i<m-1; i++){
  42. int j = upper_bound(begin(b)+i+1, end(b), 2*b[i] ) - begin(b);
  43.  
  44. ans += (j-1)-i;
  45. }
  46.  
  47. return ans;
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. void solve() {
  60.  
  61. int n;
  62. cin>>n;
  63. a.resize(n);
  64.  
  65. for(int i=0; i<n; i++) cin >> a[i];
  66. cout << consistency(n) << endl;
  67.  
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. int32_t main() {
  77. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  78.  
  79. int t = 1;
  80. // cin >> t;
  81. while (t--) {
  82. solve();
  83. }
  84.  
  85. return 0;
  86. }
Success #stdin #stdout 0.01s 5324KB
stdin
5
-1 2 1 -1 1 
3
2 5 -3
2
3 6
3
0 100 -100
stdout
3