# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
873993 | The_Samurai | Star triangles (IZhO11_triangle) | C++17 | 608 ms | 31096 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.
// #pragma GCC optimize("Ofast,O3")
// #pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
set<pair<int, int>> st;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
st.emplace(x, y);
}
ll ans = 0;
map<int, vector<int>> mpx, mpy;
for (auto [x, y]: st) {
mpx[x].emplace_back(y);
mpy[y].emplace_back(x);
}
for (auto &it: mpx) sort(it.second.begin(), it.second.end());
for (auto &it: mpy) sort(it.second.begin(), it.second.end());
for (auto [x, y]: st) {
int px = upper_bound(mpx[x].begin(), mpx[x].end(), y) - mpx[x].begin();
int py = upper_bound(mpy[y].begin(), mpy[y].end(), x) - mpy[y].begin();
ans += 1ll * ((int) mpx[x].size() - px) * ((int) mpy[y].size() - py);
ans += 1ll * (px - 1) * ((int) mpy[y].size() - py);
ans += 1ll * ((int) mpx[x].size() - px) * (py - 1);
ans += 1ll * (px - 1) * (py - 1);
}
cout << ans;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q = 1;
// cin >> q;
while (q--) {
solve();
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |