Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<vector>
- #include<algorithm>
- #include<unordered_map>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- freopen("tamgiac.inp", "r", stdin);
- //freopen("tamgiac.out", "w", stdout);
- long n;
- cin >> n;
- vector<long> a(n), b;
- unordered_map<long, long> cnt;
- for (auto &i : a)
- cin >> i, b.push_back(i*i), ++cnt[b.back()];;
- // Process
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- long obt = 0, tag = 0, rig = 0;
- for (long i = 1; i < n-1; ++i)
- for (long j = 0; j < i; ++j)
- {
- // Tim nhung bo ba la tam giac
- long pst = prev(lower_bound(a.begin()+i+1, a.end(), a[i]+a[j]))-a.begin();
- if (pst == -1) continue;
- tag += pst-i;
- // Tim nhung bo ba la tam giac vuong
- rig += cnt[b[i]+b[j]];
- long pst2 = upper_bound(b.begin()+i+1, b.end(), b[i]+b[j])-b.begin();
- // Tim nhung bo ba la tam gia tu
- if (pst2 > pst) continue;
- obt += pst-pst2+1;
- }
- cout << tag-obt-rig << ' ' << rig << ' ' << obt << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment