-
Notifications
You must be signed in to change notification settings - Fork 3
/
F.cpp
74 lines (61 loc) · 1.59 KB
/
F.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
struct Point{
LL x, y;
Point operator-(const Point &t) const {
return {x - t.x, y - t.y};
}
LL operator^(const Point &t) const {
return x * t.y - y * t.x;
}
};
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<Point> p(n);
for(int i = 0; i < n; i++){
cin >> p[i].x >> p[i].y;
}
auto C2 = [&](int x){
return x * (x - 1) / 2;
};
auto quad = [&](Point p){
if (p.y < 0) return 1;
if (p.y > 0) return 3;
if (p.x > 0) return 2;
return 0;
};
LL ans = 0;
for(int i = 0; i < n; i++){
vector<Point> q;
for(int j = 0; j < n; j++){
if (i != j){
q.push_back(p[j] - p[i]);
}
}
sort(q.begin(), q.end(), [&](Point a, Point b){
int q1 = quad(a), q2 = quad(b);
if (q1 != q2) return q1 < q2;
return (a ^ b) > 0;
});
const int m = q.size();
q.resize(2 * m);
for(int j = 0; j < m; j++) q[j + m] = q[j];
for(int j = 0, k = 0; j < m; j++){
k = max(k, j + 1);
while(k < j + m && (q[j] ^ q[k]) > 0) k++;
int c1 = k - j - 1;
int c2 = m - 1 - c1;
ans += 2LL * C2(c1) * C2(c2);
}
}
cout << ans / 4 << '\n';
}