Submission #333818

#TimeUsernameProblemLanguageResultExecution timeMemory
333818limabeansStar triangles (IZhO11_triangle)C++17
100 / 100
1014 ms20560 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; int n; vector<pair<int,int>> a; map<int,vector<int>> byX, byY; int getLess(int x, const vector<int>& w) { auto iter = lower_bound(w.begin(),w.end(),x); if (iter==w.begin()) return 0; --iter; return iter - w.begin() + 1; } int getGreater(int x, const vector<int>& w) { auto iter = upper_bound(w.begin(),w.end(),x); return w.end() - iter; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; a.resize(n); for (int i=0; i<n; i++) { cin>>a[i].first>>a[i].second; byX[a[i].first].push_back(a[i].second); byY[a[i].second].push_back(a[i].first); } for (auto &p: byX) { sort(p.second.begin(), p.second.end()); } for (auto &p: byY) { sort(p.second.begin(), p.second.end()); } ll res = 0; for (auto p: a) { int x = p.first; int y = p.second; res += 1ll*getLess(y,byX[x])*getLess(x,byY[y]); res += 1ll*getLess(y,byX[x])*getGreater(x,byY[y]); res += 1ll*getGreater(y,byX[x])*getLess(x,byY[y]); res += 1ll*getGreater(y,byX[x])*getGreater(x,byY[y]); } cout<<res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...