题目描述

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. CF 1008B Turn the Rectangles(水题+贪心)

    There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it ...

  2. 安装VS的过程

    软件工程学习到第三周,我们需要下载一个新的软件,用来进行软件测试.刚开始知道的时候觉得没甚么,不就是下个软件吗!有什么大不了的,分分钟搞定的事.可是想象很美好,现实很骨感.这是一个巨大的工作量呀,不仅 ...

  3. Android:有关下拉菜单导航的学习(供自己参考)

    Android:有关==下拉菜单导航==的学习 因为先前的学习都没想着记录自己的学习历程,所以该博客才那么迟才开始写. 内容: ==下拉菜单导航== 学习网站:android Spinner控件详解 ...

  4. 基础系列(6)—— C#类和对象

    一.类介绍       类(class)是C#类型中最基础的类型.类是一个数据结构,将状态(字段)和行为(方法和其他函数成员)组合在一个单元中.类提供了用于动态创建类实例的定义,也就是对象(objec ...

  5. 第二次作业——个人项目实战(sudoku)

    第二次作业--个人项目实战(sudoku) 一.作业要求地址 第二次作业--个人项目实战 二.Github项目地址 softengineering1--sudoku 三.PSP表格估计耗时 PSP2. ...

  6. Codeforces Round #287 (Div. 2) E. Breaking Good 最短路

    题目链接: http://codeforces.com/problemset/problem/507/E E. Breaking Good time limit per test2 secondsme ...

  7. JSON.parse与eval

    文章:JSON.parse 与 eval() 对于解析json的问题 json的标准格式:{"name":"jobs"}   名字和值都必须用双引号引起来.

  8. playbook详解—YAML格式的文本

    在playbook中有一些核心的指令 hosts:指明命令运行在哪个node之上 remote_user:在远端的node之上以什么用户的身份运行命令 var:给模板传递变量值 tasks:指明需要执 ...

  9. 桥接,NAT,Host Only的区别

    桥接,NAT,Host Only的区别   一.Brigde——桥接 :默认使用VMnet0fish批注:只要在虚拟机中将IP设对,即使宿主机的IP是错的,也可以通信.但是如此物理网卡被禁用了,则不能 ...

  10. bootstrap心得

    最近在弄个人的博客,之前对bootstrap的使用老是感觉使用的一般 幸好在看了慕课网的一个老师的实例教程之后,才感觉是真正对前端使用bootstrap有了一点理解 首先就是. 这些标签,其实都是相当 ...