麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Tsinghua OJ:燈塔(手排+歸并排序)

2019-11-14 09:44:31
字體:
來源:轉載
供稿:網友

燈塔(LightHouse)


Description

As shown in the following figure, If another lighthouse is in gray area, they can beacon each other.

For example, in following figure, (B, R) is a pair of lighthouse which can beacon each other, while (B, G), (R, G) are NOT.

Input

1st line: N

2nd ~ (N + 1)th line: each line is X Y, means a lighthouse is on the point (X, Y).

Output

How many pairs of lighthourses can beacon each other

( For every lighthouses, X coordinates won't be the same , Y coordinates won't be the same )

Example

Input

32 24 35 1

Output

1

Restrictions

For 90% test cases: 1 <= n <= 3 * 105

For 95% test cases: 1 <= n <= 106

For all test cases: 1 <= n <= 4 * 106

For every lighthouses, X coordinates won't be the same , Y coordinates won't be the same.

1 <= x, y <= 10^8

Time: 2 sec

Memory: 256 MB

Hints

The range of int is usually [-231, 231 - 1], it may be too small.

描述

海上有許多燈塔,為過路船只照明。

(圖一)

如圖一所示,每個燈塔都配有一盞探照燈,照亮其東北、西南兩個對頂的直角區域。探照燈的功率之大,足以覆蓋任何距離。燈塔本身是如此之小,可以假定它們不會彼此遮擋。

(圖二)

若燈塔A、B均在對方的照亮范圍內,則稱它們能夠照亮彼此。比如在圖二的實例中,藍、紅燈塔可照亮彼此,藍、綠燈塔則不是,紅、綠燈塔也不是。

現在,對于任何一組給定的燈塔,請計算出其中有多少對燈塔能夠照亮彼此。

輸入

共n+1行。

第1行為1個整數n,表示燈塔的總數。

第2到n+1行每行包含2個整數x, y,分別表示各燈塔的橫、縱坐標。

輸出

1個整數,表示可照亮彼此的燈塔對的數量。

樣例

見英文題面

限制

對于90%的測例:1 ≤ n ≤ 3×105

對于95%的測例:1 ≤ n ≤ 106

全部測例:1 ≤ n ≤ 4×106

燈塔的坐標x, y是整數,且不同燈塔的x, y坐標均互異

1 ≤ x, y ≤ 10^8

時間:2 sec

內存:256 MB

這里歸并排序只能過掉百分之九十五的樣例;

發博客的目的是保存自己的歸并模板具體優化需要用到樹狀數組
#include<stdio.h>#define maxn 4000005struct node{	long long x,y;}a[maxn];long long s[maxn],ss[maxn],count;void qsort(node aa[],int l,int r){	if(l<r)	{	int x=l,y=r;	node temp;	temp.x=aa[x].x;	temp.y=aa[x].y;	int  t=aa[x].x;	while(x<y)	{		while(x<y && t<aa[y].x)			y--;		a[x].x=a[y].x;		a[x].y=a[y].y;		while(x<y && aa[x].x<t)			x++;		a[y].x=a[x].x;		a[y].y=a[x].y;	}	a[x].x=temp.x;	a[x].y=temp.y;	qsort(aa,l,x-1);	qsort(aa,x+1,r);	}}void merge(long long *s,long long *ss,int l,int mid,int r){	int i=l,j=mid+1;	int k=l;	while(i<=mid && j<=r)	{		if(s[i]<s[j])		{			ss[k++]=s[i++];			count+=r-j+1;//求順序對		}		else			ss[k++]=s[j++];	}	while(i<=mid)		ss[k++]=s[i++];	while(j<=r)		ss[k++]=s[j++];	for(i=l;i<=r;i++)		s[i]=ss[i];}void mergesort(long long *s,long long *ss,int l,int r){	int mid=(l+r)/2;	if(l<r)	{		mergesort(s,ss,l,mid);		mergesort(s,ss,mid+1,r);		merge(s,ss,l,mid,r);	}}int  main(){	int n,i;	scanf("%d",&n);	for(i=1;i<=n;i++)		scanf("%lld%lld",&a[i].x,&a[i].y);	qsort(a,1,n);	for(i=1;i<=n;i++)		s[i]=a[i].y;	mergesort(s,ss,1,n);	PRintf("%lld/n",count);}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 草碰人人 | 成人性视频免费网站下载软件 | 国产成人高清在线 | wwwxxx视频| 成人做爰s片免费看网站 | 欧美成人精品一区二区男人小说 | 狠狠操电影| 成年免费视频黄网站在线观看 | 爱操影院| 欧美综合日韩 | www.91操| 日本黄色不卡视频 | 国产精品视频免费在线观看 | 羞羞视频免费网站含羞草 | 免费看真人a一级毛片 | 污片在线观看视频 | 国产亚洲自拍一区 | 久久久久久中文字幕 | 亚洲影院在线 | 国产羞羞网站 | 精品国产99久久久久久宅男i | 国产人成精品一区二区三 | 国产成人精品无人区一区 | 看中国一级毛片 | 日本a∨精品中文字幕在线 被啪羞羞视频在线观看 | 老司机免费福利午夜入口ae58 | 国产在线观看一区二区三区 | 色交视频 | 久草在线观看资源 | 刘亦菲一区二区三区免费看 | 免费观看欧美一级片 | 久久久久久麻豆 | 久久精品一级 | 国产成人强伦免费视频网站 | 久久9色| 成人在线视频在线观看 | 性欧美大战久久久久久久免费观看 | 久久成年人视频 | 成人精品视频在线 | 成熟女人特级毛片www免费 | 欧美成人午夜 |