题目描述

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. 树状数组怒刷sum!!!(前缀和应用)

    我们知道我们利用树状数组维护的是存到其中的a[ ]数组,但是我们做题需要的是sum[ ]数组,这才是我们真正需要的有用的信息,写这篇博客的目的便是整理一下sum数组是怎么样来应用解题的. 1. Sta ...

  2. tensorflow之曲线拟合

    视频链接:https://morvanzhou.github.io/tutorials/machine-learning/ML-intro/ 1.定义层 定义 add_layer() from __f ...

  3. Java微笔记(9)

    使用 Date 和 SimpleDateFormat 类表示时间 处理日期和时间的相关数据,可以使用 java.util 包中的 Date 类 使用 Date 类的默认无参构造方法创建出的对象就代表当 ...

  4. Alpha冲刺——第九天

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

  5. yum 安装php环境

    centos下安装php环境 | 浏览:3831 | 更新:2014-11-04 17:01 1 2 3 分步阅读 在网上看了很多,很多都不能用,所以就把能用的实践下,过程记录下,方便自己和网友以后查 ...

  6. kafka 基础知识梳理-kafka是一种高吞吐量的分布式发布订阅消息系统

    一.kafka 简介 今社会各种应用系统诸如商业.社交.搜索.浏览等像信息工厂一样不断的生产出各种信息,在大数据时代,我们面临如下几个挑战: 如何收集这些巨大的信息 如何分析它 如何及时做到如上两点 ...

  7. centOS 中安装 Redis

    之前安装过了 jdk,mysql,tomcat,这次安装 Redis,最开始是将 redis 安装在 windows 下 run 的,这时安装在 Linux 里面试试. 1 . 首先得安装 c环境,用 ...

  8. 有道云笔记web版本居然不支持火狐

    好尴尬的火狐呀....

  9. HDU2486_A simple stone game

    这个题目是这样的,一堆石子有n个,首先第一个人开始可以去1-(n-1)个,接下来两人轮流取石子,每个人可取的石子数必须是一个不超过上一次被取的石子的K倍的整数. 现在求对于一堆数量为n的石子是否为必胜 ...

  10. jquery 集合注意点