Submission #522963

#TimeUsernameProblemLanguageResultExecution timeMemory
522963TheKingAleksStar triangles (IZhO11_triangle)C++14
100 / 100
164 ms11808 KiB
#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 timeMemoryGrader output
Fetching results...