Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "TRIACU"
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- constexpr int N = 2e3 + 5;
- int n;
- struct Segment
- {
- int l, c;
- bool operator<(const Segment &a) const
- {
- return l < a.l;
- }
- } a[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- cin >> a[i].l >> a[i].c;
- sort(a + 1, a + n + 1);
- }
- bool Get(const ll &x, const ll &y, const ll &z)
- {
- return x * x + y * y > z * z && (x - y) * (x - y) < z * z;
- }
- bool Check(ll x, ll y, ll z)
- {
- // Bất đẳng thức tam giác
- if (x + y <= z || y + z <= x || x + z <= y)
- return false;
- // Kiểm tra xem có phải tam giác nhọn không
- return Get(x, y, z) && Get(y, z, x) && Get(x, z, y);
- }
- void Sub_1()
- {
- ll ans(0);
- // Duyệt mọi cặp độ dài
- for (int i = 1; i <= n; ++i)
- for (int j = i + 1; j <= n; ++j)
- for (int t = j + 1; t <= n; ++t)
- if (Check(a[i].l, a[j].l, a[t].l))
- ans += 1ll * a[i].c * a[j].c * a[t].c;
- cout << ans;
- }
- void Sub_2()
- {
- ll ans(0);
- for (int i = 1; i < n; ++i) // Cố định i
- {
- ll cnt(a[i + 1].c);
- // Hai con trỏ
- for (int j = i + 1, t = i + 2; j < n; ++j)
- {
- cnt -= a[j].c;
- while (t <= n && Check(a[i].l, a[j].l, a[t].l))
- cnt += a[t++].c;
- ans += 1ll * a[i].c * a[j].c * cnt;
- }
- }
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- Read();
- if (n <= 200)
- Sub_1();
- else
- Sub_2();
- }
Add Comment
Please, Sign In to add comment