题目描述

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. 20181113-7 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 05

    作业要求https://edu.cnblogs.com/campus/nenu/2018fall/homework/2387 版本控制https://git.coding.net/lglr2018/F ...

  2. 《JavaScript》函数

    function foo(a,b){return a+b}//函数申明 var foo=function(){}//函数表达式赋值 var foo=new Function('a','b','retu ...

  3. Alpha冲刺——第五天

    Alpha第五天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...

  4. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp

    题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...

  5. 软工网络15个人作业4--alpha阶段个人总结

    一.个人总结 自我评价表 类别 具体技能和面试问题 现在的回答 毕业找工作 语言 最拿手的语言之一,代码量是多少 java,代码量大概两三千行吧 语言 最拿手的语言之二,代码量是多少 python,代 ...

  6. java的reflection

    Reflection是Java 程序开发语言的特征之一,它允许运行中的 Java 程序对自身进行检查,或者说"自审",并能直接操作程序的内部属性.例如,使用它能获得 Java 类中 ...

  7. 操作系统之实验二Step1-有序顺序表

    实验二Step1-有序顺序表 专业:商业软件工程     班级:商软2班     姓名:甘佳萍     学号:201406114207 实验要求:初始化 输入数组元素个数. 输入n个数,排序输出. 存 ...

  8. 数学口袋精灵感受与BUG

    232朱杰 http://www.cnblogs.com/alfredzhu https://github.com/alfredzhu/ 组长,团队 230蔡京航 http://www.cnblogs ...

  9. 一次性无重复配置VS项目插件属性的方法

    在VS中需要使用opencv开源库或mysql等数据库时,为了能使用开源库或数据库的语言,需要添加库文件和包含目录等等.然而直接在[解决方案管理器]-->属性中配置的话,写下一个项目(解决方案) ...

  10. 第198天:js---内置对象的原型链和其他知识

    一.内置对象的原型链 1.Object原型 function test() {} alert(test.toString()); //新增属性 Object.prototype.mytest = fu ...