灯塔(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

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.

视频里有讲解我尽然没看到,醉了。

就是求一下逆序对就行。

 #include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
const int max_size = * 1e6;
LL y_val[max_size];
LL tmp_arry[max_size];
///加速代码,why 百度
const int SZ = <<;
struct fastio{
char inbuf[SZ];
char outbuf[SZ];
fastio(){
setvbuf(stdin,inbuf,_IOFBF,SZ);
setvbuf(stdout,outbuf,_IOFBF,SZ);
}
}io;
struct Point
{
LL x, y;
} p[max_size]; int cmp(const void *a, const void *b)
{
struct Point *c = (Point *)a;
struct Point *d = (Point *)b;
if(c->x != d->x)
return c->x - d->x;
else
return d->y - c->y;
} LL Merge(LL *arr, LL beg, LL mid, LL end, LL *tmp_arr)
{
memcpy(tmp_arr+beg, arr+beg, sizeof(LL)*(end - beg + ));
LL i = beg;
LL j = mid+;
LL k = beg;
LL inversion = ;
while(i <= mid && j <= end)
{
if(tmp_arr[i] <= tmp_arr[j])
arr[k++] = tmp_arr[i++];
else
{
arr[k++] = tmp_arr[j++];
inversion += mid - i + ;
}
} while(i <= mid)
arr[k++] = tmp_arr[i++];
while(j <= end)
arr[k++] = tmp_arr[j++];
return inversion;
} LL MergeInversion(LL *arr, LL beg, LL end, LL *tmp_arr)
{
LL inversions = ;
if(beg < end)
{
LL mid = (beg + end) >> ;
inversions += MergeInversion(arr, beg, mid, tmp_arr);
inversions += MergeInversion(arr, mid+, end, tmp_arr);
inversions += Merge(arr, beg, mid, end, tmp_arr);
}
return inversions;
} int main()
{
LL n;
cin >> n;
for(int i = ; i < n; i++)
{
cin >> p[i].x >> p[i].y;
} qsort(p, n, sizeof(p[]), cmp);
for(int i = ; i < n; i++)
{
y_val[i] = p[i].y;
} memcpy(tmp_arry, y_val, sizeof(LL)*n);
cout << n*(n-) / - MergeInversion(y_val, , n-, tmp_arry) << endl;
return ;
}

然后再对代码进行优化吧,我的这段过不了最后一个点。因为多做了排序操作,没必要。

清华学堂 LightHouse的更多相关文章

  1. 清华学堂 列车调度(Train)

    列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...

  2. 清华学堂 Range

    Descriptioin Let S be a set of n integral points on the x-axis. For each given interval [a, b], you ...

  3. 记2014“蓝桥杯全国软件大赛&quot;决赛北京之行

    5月29,30日 最终到了这一天.晚上有数据结构课,10点多的火车,我们就没有去上课,下午在宿舍里收拾东西,晚上8点左右从南校出发,9点半多到达火车站和老师学长学姐们会和. 第一次去北京,第一次买的卧 ...

  4. WEB入门三 CSS样式表基础

    学习内容 Ø        CSS的基本语法 Ø        CSS选择器 Ø        常见的CSS样式 Ø        网页中3种使用CSS的方式 能力目标 Ø        理解CSS的 ...

  5. 【推荐】适合本科生的网络公开课(MOOC为主),不断更新……

    题记:身在海大(湛江),是幸运还是不幸,每一个人有自己的定义.人生不能再来一次,唯有把握当下.提高自己,才可能在不能拼爹的年代靠自身实力前行.或许,我们做不了富二代.但我们每一个人.都有机会成为富二代 ...

  6. 教育O2O在学校落地,学堂在线瞄准混合式教学

    (大讲台—国内首个it在线教育混合式自适应学习平台.) 进入2015年,互联网教育圈最火的词非“教育O2O”莫属.不断刷新的融资金额和速度,不断曝光的正面和负面新闻,都让教育O2O公司赚足了眼球.然并 ...

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

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

  8. HTML5学堂,感谢您一年的陪伴(上)

    在HTML学堂将满一周岁之际,感谢再过去的一年里支持和关注它的每一个小伙伴.有了你们的支持,HTML5学堂才能更好的走下去.我们将会把这一年的积累重新体现在HTML5学堂的官网上.HTML5学堂将会全 ...

  9. 【Java】深深跪了,OJ题目Java与C运行效率对比(附带清华北大OJ内存计算的对比)

    看了园友的评论之后,我也好奇清橙OJ是怎么计算内存占用的.重新测试的情况附在原文后边. -------------------------------------- 这是切割线 ----------- ...

随机推荐

  1. Transmission : 如何在Fedora下使用BT下载

    先讲讲BT协议的名词: Glossary of BitTorrent terms Transmission 介绍 BT下载客户端 特点: 支持BT下载(.torrent 种子) 或者 磁链( magn ...

  2. c语言求数组长度

    在定义数组的函数内 int arr[] = {12.12}; int length; length = ]; 在别的函数中作为引用数据类型引入时,以上方法失效: 解决方法1:再传一个int 类型的长度 ...

  3. Python之路【第二十篇】Tornado框架

    Tornado Tornado是使用Python编写的一个强大的.可扩展的Web服务器.它在处理严峻的网络流量时表现得足够强健,但却在创建和编写时有着足够的轻量级,并能够被用在大量的应用和工具中. 我 ...

  4. 百度编辑器 ueditor 内容编辑自动套P标签,及p标签 替换

    如图,红框为回车键和shift+回车 :    ===>>  ueditor.all.js中: 1: 搜索修改成false:allowDivTransToP: false 再搜索并修改以下 ...

  5. 自定义cell自适应高度

    UITableView在许多App种被大量的应用着,呈现出现的效果也是多种多样的,不能局限于系统的一种样式,所以需要自定义cell 自定义cell呈现的内容也是多种多样的,内容有多有少,所以需要一种能 ...

  6. ActiveMQ消息存储持久化

    --------------------------------------------------------------------------------------------------- ...

  7. [Search Engine] 搜索引擎分类和基础架构概述

    大家一定不会多搜索引擎感到陌生,搜索引擎是互联网发展的最直接的产物,它可以帮助我们从海量的互联网资料中找到我们查询的内容,也是我们日常学习.工作和娱乐不可或缺的查询工具.之前本人也是经常使用Googl ...

  8. PHP获取当前域名$_SERVER['HTTP_HOST']和$_SERVER['SERVER_NAME']的区别

    开发站群软件,用到了根据访问域名判断子站点的相关问题,PHP获取当前域名有两个变量 $_SERVER['HTTP_HOST'] 和 $_SERVER['SERVER_NAME'],两者的区别以及哪个更 ...

  9. [BZOJ2761][JLOI2011]不重复数字

    [BZOJ2761][JLOI2011]不重复数字 试题描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复 ...

  10. python file

    >>> help(open) Help on built-in function open in module __builtin__: open(...) open(name[, ...