답안 #867672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867672 2023-10-29T06:04:58 Z sleepntsheep 별들과 삼각형 (IZhO11_triangle) C++17
100 / 100
134 ms 4944 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 300005

int n, c[N], C, b[N];
array<int, 2> a[N]; ll z;

int main()
{
    ShinLena;
    for (int i = (cin >> n, 0); i < n; ++i) cin >> a[i][0] >> a[i][1], c[C++] = a[i][1];
    sort(c, c+C);
    for (int i = 0; i < n; ++i) ++b[a[i][1] = lower_bound(c, c+C, a[i][1]) - c];
    sort(a, a+n); n = unique(a, a+n) - a;
    for (ll f, e = 0, d = 0, i = 0, l = -1; i < n; ++i)
    {
        f = a[i][0] == l;
        l += (a[i][0] - l) * !f, d *= f, e *= f;
        z += d + (b[a[i][1]] - 1ll) * e;
        ++e, d += b[a[i][1]] - 1;
    }
    cout << z;
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 3 ms 612 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 42 ms 3260 KB Output is correct
16 Correct 45 ms 3524 KB Output is correct
17 Correct 42 ms 3448 KB Output is correct
18 Correct 43 ms 3420 KB Output is correct
19 Correct 125 ms 4688 KB Output is correct
20 Correct 87 ms 4180 KB Output is correct
21 Correct 133 ms 4944 KB Output is correct
22 Correct 134 ms 4932 KB Output is correct