# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
522963 | TheKingAleks | Star triangles (IZhO11_triangle) | C++14 | 164 ms | 11808 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |