# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
5393 | baneling100 | 별들과 삼각형 (IZhO11_triangle) | C++98 | 188 ms | 10460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <algorithm>
#define inf 0x7fffffff
using namespace std;
pair <int,int> p1[300002];
pair <int,int> p2[300002];
int n, xcnt[300001], ycnt[300001], px[300001], py[300001];
long long ans;
void input(void)
{
int i, x, y;
scanf("%d",&n);
for(i=1 ; i<=n ; i++)
{
scanf("%d %d",&x,&y);
p1[i]=make_pair(x,i);
p2[i]=make_pair(y,i);
}
sort(p1+1,p1+n+1);
sort(p2+1,p2+n+1);
}
void process(void)
{
int i;
p1[0].first=p2[0].first=inf;
for(i=1 ; i<=n ; i++)
{
if(p1[i].first==p1[i-1].first)
xcnt[i]=xcnt[i-1]+1;
else
xcnt[i]=1;
if(p2[i].first==p2[i-1].first)
ycnt[i]=ycnt[i-1]+1;
else
ycnt[i]=1;
}
for(i=n ; i>=1 ; i--)
{
if(xcnt[i]==xcnt[i+1]-1)
xcnt[i]=xcnt[i+1];
if(ycnt[i]==ycnt[i+1]-1)
ycnt[i]=ycnt[i+1];
px[p1[i].second]=xcnt[i];
py[p2[i].second]=ycnt[i];
}
for(i=1 ; i<=n ; i++)
ans+=((long long)px[i]-1)*(py[i]-1);
}
void output(void)
{
printf("%lld",ans);
}
int main(void)
{
input();
process();
output();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |