题目描述

Given a registry of all houses in your state or province, you would like to know the minimum size of an axis-aligned square zone such that every house in a range of addresses lies in the zone or on its border. The zoning is a bit lenient and you can ignore any one house from the range to make the zone smaller.
The addresses are given as integers from 1..n. Zoning requests are given as a consecutive range of houses. A valid zone is the smallest axis-aligned square that contains all of the points in the range,ignoring at most one.
Given the (x, y) locations of houses in your state or province, and a list of zoning requests, you must figure out for each request: What is the length of a side of the smallest axis-aligned square zone that contains all of the houses in the zoning request, possibly ignoring one house?

输入

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will begin with a line containing two integers n and q (1 ≤ n, q ≤ 105 ), where n is the number of houses, and q is the number of zoning requests.
The next n lines will each contain two integers, x and y (−109 ≤ x, y ≤ 109 ), which are the (x,y) coordinates of a house in your state or province. The address of this house corresponds with the order in the input. The first house has address 1, the second house has address 2, and so on. No two houses will be at the same location.
The next q lines will contain two integers a and b (1 ≤ a < b ≤ n), which represents a zoning request for houses with addresses in the range [a..b] inclusive.

输出

Output q lines. On each line print the answer to one of the zoning requests, in order: the side length of the smallest axis-aligned square that contains all of the points of houses with those addresses, if at most one house can be ignored.

样例输入

3 2
1 0
0 1
1000 1
1 3
2 3

样例输出

1
0
给出n个点的坐标和q个询问。每个询问给出一段区间[l,r],找出一个最小的中心在原点的正方形使得包含区间内所有的点,但是可以忽略区间内的一个点.

如果不考虑忽略一个点的话每次询问只要找出区间内点的最大最小横纵坐标就可以。忽略一个点一定优于或等于不忽略,所以直接考虑忽略哪个点。需要考虑的最多只有四个点,横坐标最大,横坐标最小,纵坐标最大,纵坐标最小。
所以对每次询问,求删掉横坐标最大,横坐标最小,纵坐标最大,纵坐标最小的点之后的答案,取最小的那个即可 线段树被卡常了qwq,写了ST还得加读入优化才能过,就很难受
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int N=2e5;
const int INF=2e9;
P xmx[N][],xmi[N][],ymx[N][],ymi[N][];
int n,m,x,y,ans;
int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void ST(int n)
{
for (int j=;(<<j)<=n;j++)
{
for (int i=;i+(<<j)-<=n;i++)
{
xmi[i][j]=min(xmi[i][j-],xmi[i+(<<(j-))][j-]);
ymi[i][j]=min(ymi[i][j-],ymi[i+(<<(j-))][j-]);
xmx[i][j]=max(xmx[i][j-],xmx[i+(<<(j-))][j-]);
ymx[i][j]=max(ymx[i][j-],ymx[i+(<<(j-))][j-]);
}
}
}
P RMQ(int l,int r,int t)
{
if (l>r)
{
if (t==||t==) return P(INF,);
else return P(-INF,);
}
int k=;
while ((<<(k+))<=r-l+) k++;
if (t==) return min(xmi[l][k],xmi[r-(<<k)+][k]);
else if (t==) return max(xmx[l][k],xmx[r-(<<k)+][k]);
else if (t==) return min(ymi[l][k],ymi[r-(<<k)+][k]);
else if (t==) return max(ymx[l][k],ymx[r-(<<k)+][k]);
}
void does(int x,int y,int pos)
{
int dx=max(RMQ(x,pos-,).first,RMQ(pos+,y,).first)-min(RMQ(x,pos-,).first,RMQ(pos+,y,).first);
int dy=max(RMQ(x,pos-,).first,RMQ(pos+,y,).first)-min(RMQ(x,pos-,).first,RMQ(pos+,y,).first);
ans=min(ans,max(dx,dy));
}
int main()
{
n=read();
m=read();
for (int i=;i<=n;i++)
{
scanf("%d%d",&xmi[i][].first,&ymi[i][].first);
xmi[i][].second=i; ymi[i][].second=i;
xmx[i][]=xmi[i][]; ymx[i][]=ymi[i][];
}
ST(n);
while(m--)
{
x=read();
y=read();
ans=INF;
does(x,y,RMQ(x,y,).second);
does(x,y,RMQ(x,y,).second);
does(x,y,RMQ(x,y,).second);
does(x,y,RMQ(x,y,).second);
printf("%d\n",ans);
}
return ;
}
 

NAIPC2018-K-Zoning Houses的更多相关文章

  1. 计蒜客 Zoning Houses(线段树区间最大次大)

    Given a registry of all houses in your state or province, you would like to know the minimum size of ...

  2. North American Invitational Programming Contest 2018

    A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...

  3. hdu 2586(LCA在线ST)

    How far away ? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): A ...

  4. hdu4085 Peach Blossom Spring

    Peach Blossom Spring http://acm.hdu.edu.cn/showproblem.php?pid=4085 Time Limit: 10000/5000 MS (Java/ ...

  5. HDOJ 4085 Peach Blossom Spring

    discriptionTao Yuanming(365-427) was a Chinese poet of Eastern Jin dynasty. One of his most famous w ...

  6. django模型操作

    Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表        

  7. POJ3928 Pingpong(统计比 K 小的个数 + 树状数组)

    Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2691   Accepted: 996 Descript ...

  8. [leetcode]265. Paint House II粉刷房子(K色可选)

    There are a row of n houses, each house can be painted with one of the k colors. The cost of paintin ...

  9. 265. Paint House II 房子涂色K种选择的版本

    [抄题]: There are a row of n houses, each house can be painted with one of the k colors. The cost of p ...

随机推荐

  1. 欢迎来怼---作业要求 20171015 beta冲刺贡献分分配规则

    一.小组信息 队名:欢迎来怼 小组成员 队长:田继平 成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文 基础分      每人占个人总分的百分之40% leangoo里面的得分    每人占个人总分里 ...

  2. L1正则化与L2正则化的理解

    1. 为什么要使用正则化   我们先回顾一下房价预测的例子.以下是使用多项式回归来拟合房价预测的数据:   可以看出,左图拟合较为合适,而右图过拟合.如果想要解决右图中的过拟合问题,需要能够使得 $ ...

  3. 第15章 磁盘配额(Quota)与高级文件系统管理

    磁盘配额(quota)的应用与实践 什么是quota 举例来说,用户的默认主文件夹是在/home下面,如果/home是个独立的分区,假设是10G,/home下有30个账号,这样30个用户共享这10G的 ...

  4. .net 错误处理

    第一步在页面中写OnError方法: protected override void OnError(EventArgs e) { Exception ex = Server.GetLastError ...

  5. Java对象创建过程补遗

    一.static修饰的东东是属于这个类的,是所有的该类的实例共享的,因此它们的初始化先于实例对象的初始化. 二.Java中没有静态构造方法,但是有静态代码块.当类中同时存在静态代码块和静态成员变量声明 ...

  6. i18n实现前端国际化(实例)

    在今日的需求中需要利用 i18n 这个框架来实现前端的国家化操作,下图是实现效果: 点击选择框实现网页上语言的切换: 下面开始实现过程: 所需工具:    - jquery-3.3.1.js 下载地址 ...

  7. zepto中$.proxy()的到底有多强大?

    好吧,其实是标题党了,哈哈,只是想总结一下工作中遇到$.proxy()的用法而已. 一.语法: $.proxy()有两种使用语法 1)$.proxy(fn,context),fn是一个函数,conte ...

  8. python 内置函数02

    1. lambda 匿名函数 lambda 参数: 返回值 #常规计算两个数相加的函数 def func(a,b): return a+b print(func(1,9)) #lambda函数 my_ ...

  9. KMPnext数组自看

    emm...无数次再看kmp了 因为一直没做相关的题..看了就忘看了就忘..emm.. next[i]表示去掉第i个元素后,自已的前缀和后缀完全匹配的最大长度 例 字符串 a b a b a b z ...

  10. 【总结】Link-Cut Tree

    这是一篇关于LCT的总结 加删边的好朋友--Link Cut Tree Link-Cut Tree,LCT的全称 可以说是从树剖引出的问题 树剖可以解决静态的修改或查询树的链上信息:那如果图会不断改变 ...