Submission #754130

# Submission time Handle Problem Language Result Execution time Memory
754130 2023-06-06T19:08:22 Z thimote75 Star triangles (IZhO11_triangle) C++14
100 / 100
418 ms 12472 KB
#include <bits/stdc++.h>

using namespace std;

using idata = vector<int>;

using ipair  = pair<int, int>;
using ipdata = vector<ipair>;

using num = long long;

idata X, Y;
ipdata stars;

int find  (idata &axis, int x) {
    int a = -1;
    int b = axis.size();

    while ( b - a > 1 ) {
        int c = (a + b) >> 1;

        if (axis[c] < x) a = c;
        else b = c;
    }

    return b;
}
int count (idata &axis, int v) {
    int l = find(axis, v);
    int r = find(axis, v + 1);

    return r - l;
}

int main () {
    int N;
    cin >> N;

    for (int i = 0; i < N; i ++) {
        int x, y;
        cin >> x >> y;

        X.push_back(x);
        Y.push_back(y);

        stars.push_back({ x, y });
    }

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    num result = 0;
    for (ipair star : stars) {
        int x = star.first;
        int y = star.second;

        num cx = count(X, x) - 1;
        num cy = count(Y, y) - 1;

        result += cx * cy;
    }

    cout << result << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 10 ms 668 KB Output is correct
13 Correct 15 ms 824 KB Output is correct
14 Correct 12 ms 836 KB Output is correct
15 Correct 131 ms 4052 KB Output is correct
16 Correct 136 ms 4448 KB Output is correct
17 Correct 135 ms 4148 KB Output is correct
18 Correct 130 ms 4056 KB Output is correct
19 Correct 373 ms 12384 KB Output is correct
20 Correct 278 ms 7844 KB Output is correct
21 Correct 398 ms 12472 KB Output is correct
22 Correct 418 ms 12448 KB Output is correct