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

3
2 2
4 3
5 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.

第一眼看到这题时第一反应是用树状数组,但是发现数据太大,开不了10的6次方的二维数组,看了别人的博客才知道是用归并排序。

先理解一下题意,要求有多少对两两互相照亮的灯塔,怎么样才能是两两互相照亮的呢,两点的斜率为正,也就是按x递增排序,y也递增。

这样咱们就可以把n个点对x进行排序,找到y有多少对是顺序对就行,这就可以用到归并排序,在对左右两个集合合并时,i,j分别为左右两个集合的

指针,如果le[i]<ri[j],正序对加上n2-j+1对,就这样去考虑。还有就是那里不能用<algorithm>,可以用stdlib.h里的qsort()。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib> using namespace std; struct w
{
int x;
int y;
}k[];
int yi[];
long long ans;
int le[],ri[]; int cmp( const void *a ,const void *b)
{
return (*(w *)a).x > (*(w *)b).x ;
} void merge(int l,int mi,int r)
{
int i,j,p,n1=mi-l+,n2=r-mi;
const int MAX=; for (int i=;i<=n1;i++)
le[i]=k[l+i-].y;
for (int i=;i<=n2;i++)
ri[i]=k[mi+i].y; le[n1+]=MAX;ri[n2+]=MAX;
i=;j=;
for (int p=l;p<=r;p++)
{
if (le[i]>ri[j])
k[p].y=ri[j++];
else
{
k[p].y=le[i++];
ans+=n2-j+;
// cout <<ans<<endl;
}
}
}
void mergesort(int l,int r)
{
if (l==r)
return;
int mid=l+(r-l)/;
mergesort(l,mid);
mergesort(mid+,r);
merge(l,mid,r);
} int main()
{
int n;
cin>>n;
for (int i=;i<n;i++)
cin>>k[i].x>>k[i].y;
qsort(k,n,sizeof(k[]),cmp);
ans=;
mergesort(,n-);
cout <<ans<<endl;
return ;
}

灯塔(LightHouse)的更多相关文章

  1. 【Tsinghua OJ】灯塔(LightHouse)问题

    描述 海上有许多灯塔,为过路船只照明.从平面上看,海域范围是[1, 10^8] × [1, 10^8] . (图一) 如图一所示,每个灯塔都配有一盏探照灯,照亮其东北.西南两个对顶的直角区域.探照灯的 ...

  2. 清华学堂 LightHouse

    灯塔(LightHouse) Description As shown in the following figure, If another lighthouse is in gray area, ...

  3. 前端性能之LightHouse

    "灯塔"(LightHouse)前端性能优化测试工具 (谷歌亲儿子) 一 灯塔v6/v7版是通过几种性能指标及不同权重来进行计分的 前端性能指标主要是根据PerformanceTi ...

  4. ACM/ICPC 之 快排+归并排序-记录顺序对(TSH OJ-LightHouse(灯塔))

    TsingHua OJ 上不能使用<algorithm>头文件,因此需要手写快排(刚开始写的时候自己就出了很多问题....),另外本题需要在给横坐标排序后,需要记录纵坐标的顺序对的数量,因 ...

  5. 谷歌性能测评工具lighthouse使用

    1.谷歌插件lighthouse的基本介绍 Lighthouse 是一个网站性能测评工具, 它是 Google Chrome 推出的一个开源自动化工具,能够对 PWA 和网页多方面的效果指标进行评测, ...

  6. 新上市Lighthouse专用芯片TS3633规格介绍

    背景介绍 Valve 有远大的愿景.它决心要把 SteamVR 追踪系统推向世界,从虚拟现实里的空间定位,到机器人领域,Valve 想为各种环境下的跟踪应用提供支持. 上个月,Valve 方面宣布会把 ...

  7. svg绘制蓝色星空,月亮,旋转灯塔

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  8. [bzoj4850][Jsoi2016]灯塔

    来自FallDream的博客,未经允许,请勿转载,谢谢. JSOI的国境线上有N一座连续的山峰,其中第ii座的高度是hi??.为了简单起见,我们认为这N座山峰排成了连续一条 直线.如果在第ii座山峰上 ...

  9. Lighthouse前端性能优化测试工具

    在前端开发中,对于自己开发的app或者web page性能的好坏,一直是让前端开发很在意的话题.我们需要专业的网站测试工具,让我们知道自己的网页还有哪些需要更为优化的方面,我自己尝试了一款工具:Lig ...

随机推荐

  1. Centos common software install

    1.本地安装soft yum localinstall xxx.rpm 2.kolourpaintyum install kolourpaint

  2. 职员时序安排lingo求解

    大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang !职员时序安排模型 题目: 一项工作一周七天都需要有人,每天所需的最少职工数为20,16,13,1 ...

  3. OCR中的倾斜矫正

    电面中被问到了做的LPR,简单的介绍了下后又问到了关于如何矫正倾斜角的问题.答得比较含糊,所以今天来补充一下. 倾斜矫正的方法有很多种,包括基于Hough变换的矫正,基于字符投影的倾角矫正,常规线性角 ...

  4. 一个poi操作实现导出功能的类

    public class ExportExcel<T> { public void exportExcel(Collection<T> dataset, OutputStrea ...

  5. 解决MVC项目中,静态html 未找到时候,404的跳转

    using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using ...

  6. IDA pro 的Python环境变量设置

    推荐使用IDA PRO6.1+Python2.6 安装完毕Python2.6后,添加如下的环境变量: PYTHONHOME=C:\Python26PATH=%PATH%;C:\Python26LIB= ...

  7. 处理通过<input type="file">的Post 请求

    [HttpPost] public ActionResult Cal() { string ExcelName = System.DateTime.Now.ToString("yyyyMMd ...

  8. HTML5的local storage存储的数据到底存到哪去了

    原文地址:http://zhidao.baidu.com/link?url=m6p5MLv0R46lDCd_Vnrry4XOMbdCwgV5fzs3tj5Jeyht1nPkAZ9OrO23njYBY1 ...

  9. Squid--hash代码分析

    #ifndef SQUID_HASH_H #define SQUID_HASH_H //几个函数和变量的别名 typedef void HASHFREE(void *); typedef int HA ...

  10. ngui点击与场景点击判断

    注:NGUI 组件上加上 BoxCollider 并设置区域大小 public void OnMouseDown()    { if (UICamera.hoveredObject == null) ...