#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
if(a.first==b.first)return a.second<b.second;
return a.first<b.first;
}
int main()
{
int n,a,b;
cin>>n;
vector<pair<int,int>>v;
unordered_map<int,int>m,m1;
for(int i=0;i<n;i++)
{
cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end(),cmp);
int i=0;
long long int sum=0;
while(i<n)
{
pair<int,int>p=v[i];
int j=i+1;
int cnt=1;
while(j<n&&v[j].first==p.first)
{
cnt++;
j++;
}
while(i<j)
{
sum+=m[v[i].second];
sum+=m1[v[i].second]*(cnt-1);
m1[v[i].second]++;
m[v[i].second]+=(cnt-1);
i++;
}
}
cout<<sum;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
368 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
472 KB |
Output is correct |
12 |
Correct |
8 ms |
1360 KB |
Output is correct |
13 |
Correct |
8 ms |
1104 KB |
Output is correct |
14 |
Correct |
8 ms |
1228 KB |
Output is correct |
15 |
Correct |
73 ms |
5820 KB |
Output is correct |
16 |
Correct |
82 ms |
6076 KB |
Output is correct |
17 |
Correct |
74 ms |
5840 KB |
Output is correct |
18 |
Correct |
71 ms |
5736 KB |
Output is correct |
19 |
Correct |
196 ms |
12976 KB |
Output is correct |
20 |
Correct |
161 ms |
9400 KB |
Output is correct |
21 |
Correct |
207 ms |
13492 KB |
Output is correct |
22 |
Correct |
209 ms |
13488 KB |
Output is correct |