답안 #873993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873993 2023-11-16T06:59:41 Z The_Samurai 별들과 삼각형 (IZhO11_triangle) C++17
100 / 100
608 ms 31096 KB
// #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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 10 ms 2228 KB Output is correct
13 Correct 9 ms 2140 KB Output is correct
14 Correct 17 ms 2796 KB Output is correct
15 Correct 179 ms 14332 KB Output is correct
16 Correct 200 ms 14932 KB Output is correct
17 Correct 169 ms 14164 KB Output is correct
18 Correct 183 ms 14568 KB Output is correct
19 Correct 478 ms 29116 KB Output is correct
20 Correct 395 ms 22716 KB Output is correct
21 Correct 608 ms 31096 KB Output is correct
22 Correct 549 ms 31096 KB Output is correct