#include <cstdio>
#include <algorithm>
using namespace std;
struct data{
int x,y,idx;
};
bool compare1(data d1,data d2){
if(d1.x==d2.x) return d1.y<d2.y;
return d1.x<d2.x;
}
bool compare2(data d1,data d2){
if(d1.y==d2.y) return d1.x<d2.x;
return d1.y<d2.y;
}
int n;
data arr[300010],table[300010];
long long res;
int main(){
int i,j,k,idx;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d %d",&arr[i].x,&arr[i].y),arr[i].idx=i;
sort(arr,arr+n,compare1);
for(i=0;i<n;i=j){
j=i+1;
while(j<n && arr[j].x==arr[i].x) j++;
for(k=i;k<j;k++){
idx=arr[k].idx; table[idx].y=j-i-1;
}
}
sort(arr,arr+n,compare2);
for(i=0;i<n;i=j){
j=i+1;
while(j<n && arr[j].y==arr[i].y) j++;
for(k=i;k<j;k++){
idx=arr[k].idx; table[idx].x=j-i-1;
}
}
for(i=0;i<n;i++){
res+=table[i].x*table[i].y;
}
printf("%lld",res);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8116 KB |
Output is correct |
2 |
Correct |
0 ms |
8116 KB |
Output is correct |
3 |
Correct |
0 ms |
8116 KB |
Output is correct |
4 |
Correct |
0 ms |
8116 KB |
Output is correct |
5 |
Correct |
0 ms |
8116 KB |
Output is correct |
6 |
Correct |
0 ms |
8116 KB |
Output is correct |
7 |
Correct |
0 ms |
8116 KB |
Output is correct |
8 |
Correct |
1 ms |
8116 KB |
Output is correct |
9 |
Correct |
1 ms |
8116 KB |
Output is correct |
10 |
Correct |
0 ms |
8116 KB |
Output is correct |
11 |
Correct |
1 ms |
8116 KB |
Output is correct |
12 |
Correct |
7 ms |
8116 KB |
Output is correct |
13 |
Correct |
4 ms |
8116 KB |
Output is correct |
14 |
Correct |
0 ms |
8116 KB |
Output is correct |
15 |
Correct |
63 ms |
8116 KB |
Output is correct |
16 |
Correct |
83 ms |
8116 KB |
Output is correct |
17 |
Correct |
75 ms |
8116 KB |
Output is correct |
18 |
Correct |
79 ms |
8116 KB |
Output is correct |
19 |
Correct |
200 ms |
8116 KB |
Output is correct |
20 |
Correct |
159 ms |
8116 KB |
Output is correct |
21 |
Correct |
200 ms |
8116 KB |
Output is correct |
22 |
Correct |
213 ms |
8116 KB |
Output is correct |