Submission #522963

# Submission time Handle Problem Language Result Execution time Memory
522963 2022-02-06T16:05:54 Z TheKingAleks Star triangles (IZhO11_triangle) C++14
100 / 100
164 ms 11808 KB
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5+2;
pair<int,int> a[MAX_N];
unordered_map<int,int> on_y;
unordered_map<int,int> on_x_res;
bool cmp(pair<int,int> e1, pair<int,int> e2)
{
    if(e1.second == e2.second) return e1.first < e2.first;
    return e1.second < e2.second;
}
int ans = 0;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x0,y0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>x0>>y0;
        a[i] = {x0,y0};
        on_y[y0]++;
    }
    sort(a,a+n,cmp);
    for(int i=0; i<n; i++)
    {
        if(on_x_res.find(a[i].first) != on_x_res.end()) ans += on_x_res[a[i].first];
        on_x_res[a[i].first] += on_y[a[i].second]-1;
    }
    on_x_res.clear();
    for(int i=n-1; i>=0; i--)
    {
        if(on_x_res.find(a[i].first) != on_x_res.end()) ans += on_x_res[a[i].first];
        on_x_res[a[i].first] += on_y[a[i].second]-1;
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 7 ms 888 KB Output is correct
13 Correct 6 ms 964 KB Output is correct
14 Correct 8 ms 1228 KB Output is correct
15 Correct 55 ms 5864 KB Output is correct
16 Correct 60 ms 6156 KB Output is correct
17 Correct 61 ms 5812 KB Output is correct
18 Correct 59 ms 5796 KB Output is correct
19 Correct 151 ms 11272 KB Output is correct
20 Correct 110 ms 8896 KB Output is correct
21 Correct 164 ms 11808 KB Output is correct
22 Correct 164 ms 11784 KB Output is correct