Iamtui1010

tamgiac.cpp

Jan 11th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<unordered_map>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     cin.tie(0)->sync_with_stdio(0);
  15.     cout.tie(0)->sync_with_stdio(0);
  16.     freopen("tamgiac.inp", "r", stdin);
  17.     //freopen("tamgiac.out", "w", stdout);
  18.     long n;
  19.     cin >> n;
  20.     vector<long> a(n), b;
  21.     unordered_map<long, long> cnt;
  22.     for (auto &i : a)
  23.         cin >> i, b.push_back(i*i), ++cnt[b.back()];;
  24.     // Process
  25.     sort(a.begin(), a.end());
  26.     sort(b.begin(), b.end());
  27.     long obt = 0, tag = 0, rig = 0;
  28.     for (long i = 1; i < n-1; ++i)
  29.         for (long j = 0; j < i; ++j)
  30.         {
  31.             // Tim nhung bo ba la tam giac
  32.             long pst = prev(lower_bound(a.begin()+i+1, a.end(), a[i]+a[j]))-a.begin();
  33.             if (pst == -1) continue;
  34.             tag += pst-i;
  35.             // Tim nhung bo ba la tam giac vuong
  36.             rig += cnt[b[i]+b[j]];
  37.             long pst2 = upper_bound(b.begin()+i+1, b.end(), b[i]+b[j])-b.begin();
  38.             // Tim nhung bo ba la tam gia tu
  39.             if (pst2 > pst) continue;
  40.             obt += pst-pst2+1;
  41.         }
  42.     cout << tag-obt-rig << ' ' << rig << ' ' << obt << nln;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment