# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333818 | limabeans | Star triangles (IZhO11_triangle) | C++17 | 1014 ms | 20560 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;
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |