# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21884 | ulna | Star triangles (IZhO11_triangle) | C++11 | 769 ms | 7132 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
// why am I so weak
int n;
int x[300055], y[300055];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &x[i], &y[i]);
}
long long res = 0ll;
vector<int> vec(n);
for (int i = 0; i < n; i++) {
vec[i] = i;
}
{
// find bottom left
sort(vec.begin(), vec.end(), [&] (int u, int v) {
if (y[u] != y[v]) return y[u] > y[v];
return x[u] > x[v];
});
map<int, int> c;
int ac = 0;
int last = -INT_MAX;
for (auto u : vec) {
if (y[u] != last) {
ac = 0;
}
res += 1ll * ac * c[x[u]];
c[x[u]]++;
ac++;
last = y[u];
}
}
{
// find bottom right
sort(vec.begin(), vec.end(), [&] (int u, int v) {
if (y[u] != y[v]) return y[u] > y[v];
return x[u] < x[v];
});
map<int, int> c;
int ac = 0;
int last = -INT_MAX;
for (auto u : vec) {
if (y[u] != last) {
ac = 0;
}
res += 1ll * ac * c[x[u]];
c[x[u]]++;
ac++;
last = y[u];
}
}
{
// find top left
sort(vec.begin(), vec.end(), [&] (int u, int v) {
if (y[u] != y[v]) return y[u] < y[v];
return x[u] > x[v];
});
map<int, int> c;
int ac = 0;
int last = -INT_MAX;
for (auto u : vec) {
if (y[u] != last) {
ac = 0;
}
res += 1ll * ac * c[x[u]];
c[x[u]]++;
ac++;
last = y[u];
}
}
{
// find top right
sort(vec.begin(), vec.end(), [&] (int u, int v) {
if (y[u] != y[v]) return y[u] < y[v];
return x[u] < x[v];
});
map<int, int> c;
int ac = 0;
int last = -INT_MAX;
for (auto u : vec) {
if (y[u] != last) {
ac = 0;
}
res += 1ll * ac * c[x[u]];
c[x[u]]++;
ac++;
last = y[u];
}
}
printf("%lld\n", res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |