/*
VENI VIDI VICI
*/
// #pragma GCC optimize("Ofast","unroll-all-loops","fast-math","no-stack-protector","give-no-fuck")
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <algorithm>
// #include <set>
// #include <map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,x, n) for (int i = (x); i < (n); ++i)
#define repr(i,x, n) for (int i = (n) - 1; i >= (x); --i)
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
// #define sum accumulate
//using i128 = __int128;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
using sll = set<ll>;
template<class T>
istream& operator>>(istream& is, vector<T>& v) {
for(auto &i:v) is>>i;
return is;
}
template<class T1,class T2>
istream& operator>>(istream& is, pair<T1,T2>& p) {
is>>p.fi>>p.se;
return is;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for(const auto &i:v) os<<i<<' ';
return os;
}
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p) {
os<<p.fi<<' '<<p.se; return os;
}
void pyn(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
void pYN(bool x)
{
cout<<(x?"Yes":"No")<<endl;
}
void pAB(bool x)
{
cout<<(x?"Alice":"Bob")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
if(b==0){
return 1;
}
ll temp=powmod(a,b/2,modulo);
if(b%2==0){
return (temp*temp)%modulo;
}
else{
return (a*((temp*temp)%modulo))%modulo;
}
}
bool Prime(ll n){
for (ll i = 2; i*i <= n; i++)
if (n % i == 0)
return false;
return (n>1);
}
void readIO() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
void solve();
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// readIO();
int uwu=1;
// cin>>uwu;
for(int tc=1;tc<=uwu;tc++) {
// cout<<"Case #"<<tc<<": ";
solve();
}
return 0;
}
const int N=3e5+10;
ll x[N],y[N],cx[N],cy[N];
vl xs[N],ys[N];
void solve()
{
ll n;
cin>>n;
vl px,py;
for(int i=0;i<n;i++)
{
cin>>x[i]>>y[i];
px.push_back(x[i]);
py.push_back(y[i]);
// st[x[i]]
}
sort(all(px));
sort(all(py));
px.resize(unique(all(px))-begin(px));
py.resize(unique(all(py))-begin(py));
for(int i=0;i<n;i++)
{
cx[i]=lower_bound(all(px),x[i])-begin(px);
cy[i]=lower_bound(all(py),y[i])-begin(py);
xs[cx[i]].push_back(cy[i]);
ys[cy[i]].push_back(cx[i]);
}
for(int i=0;i<N;i++)
{
sort(all(xs[i]));
sort(all(ys[i]));
}
ll ans=0;
for(int i=0;i<n;i++)
{
// auto it=end(xs[cx[i]])-upper_bound(all(xs[cx[i]]),cy[i]);
ll it=xs[cx[i]].size() - (upper_bound(all(xs[cx[i]]),cy[i])-lower_bound(all(xs[cx[i]]),cy[i]));
ll it1=ys[cy[i]].size() - (upper_bound(all(ys[cy[i]]),cx[i])-lower_bound(all(ys[cy[i]]),cx[i]));
// auto it1=upper_bound(all(ys[cy[i]]),cx[i])-begin(ys[cy[i]]);
// cout<<"For "<<i<<' '<<x[i]<<' '<<y[i]<<' '<<it<<' '<<it1<<endl;
ans+=(1ll*it*it1);
// all y such (x,y) (x,y') y<y'
// all x such (x,y) (x',y) x'<x
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
triangle.cpp: In function 'void readIO()':
triangle.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
triangle.cpp:91:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |