답안 #426148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426148 2021-06-13T14:41:51 Z SuckTinHock 별들과 삼각형 (IZhO11_triangle) C++14
100 / 100
425 ms 40124 KB
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second

using namespace std;
typedef pair<int,int> Point;
Point P[300005];
int n;
int cntx[1000005], cnty[1000005];

void compress()
{
    vector<int> A;
    for (int i = 1; i <= n; ++i)
    {
        A.push_back(P[i].x);
        A.push_back(P[i].y);
    }
    sort(A.begin(),A.end());
    for (int i = 1; i <= n; ++i)
    {
        P[i].x = lower_bound(A.begin(),A.end(),P[i].x) - A.begin();
        P[i].y = lower_bound(A.begin(),A.end(),P[i].y) - A.begin();
    }
}

void xuly()
{
    int res = 0;
    compress();
    sort(P+1,P+n+1);
    vector<pair<Point,int> > PP;
    for (int i = 1; i <= n; ++i)
    {
        PP.push_back({P[i],1});
        while (i+1 <= n && P[i] == P[i+1]) ++PP.back().y, ++i;
        cntx[P[i].x] += PP.back().y;
        cnty[P[i].y] += PP.back().y;
    }
    for (pair<Point,int> T : PP)
    {
        Point X = T.x;
        int cnt = T.y;
        res += (cntx[X.x] - cnt) * (cnty[X.y] - cnt) * cnt;
    }
    cout << res;
}

void nhap()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> P[i].x >> P[i].y;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    nhap();
    xuly();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 8 ms 1484 KB Output is correct
13 Correct 7 ms 1440 KB Output is correct
14 Correct 9 ms 1612 KB Output is correct
15 Correct 94 ms 11500 KB Output is correct
16 Correct 101 ms 12012 KB Output is correct
17 Correct 93 ms 11440 KB Output is correct
18 Correct 103 ms 11404 KB Output is correct
19 Correct 293 ms 33144 KB Output is correct
20 Correct 202 ms 24936 KB Output is correct
21 Correct 425 ms 40108 KB Output is correct
22 Correct 322 ms 40124 KB Output is correct