#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const ll mod = 998244353 ;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
bool cmp(pair<int,int> a ,pair<int,int> b){
return a.vs < b.vs;
}
void solve(){
int n;
cin >> n;
vector<pair<int,int>> v;
for(int i = 0; i < n; i++){
int x , y;
cin >> x >> y;
v.pb(mp(x,y));
}
sort(all(v) , cmp);
ll ans = 0;
map<int,ll> m;
for(int i = 0; i < n; i++){
ll cnt = 1;
int j = i + 1;
while(j < n && v[j].vs == v[i].vs){
j++;
cnt++;
}
i = j - 1;
m[v[i].vs] = cnt;
}
sv(v);
for(int i = 0; i < n; i++){
ll cnt = 1;
int j = i + 1;
while(j < n && v[j].vf == v[i].vf){
j++;
cnt++;
}
for(int k = i; k < j; k++){
ans += (cnt - 1LL) * (m[v[k].vs]-1LL);
}
i = j - 1;
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("rblock.in", "r", stdin);
//freopen("rblock.out", "w", stdout);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
236 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
6 ms |
1092 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
14 |
Correct |
7 ms |
1100 KB |
Output is correct |
15 |
Correct |
62 ms |
5076 KB |
Output is correct |
16 |
Correct |
67 ms |
5428 KB |
Output is correct |
17 |
Correct |
63 ms |
5168 KB |
Output is correct |
18 |
Correct |
67 ms |
5112 KB |
Output is correct |
19 |
Correct |
173 ms |
10504 KB |
Output is correct |
20 |
Correct |
121 ms |
8204 KB |
Output is correct |
21 |
Correct |
182 ms |
11168 KB |
Output is correct |
22 |
Correct |
180 ms |
11244 KB |
Output is correct |