题目描述

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][20],xmi[N][20],ymx[N][20],ymi[N][20];
int n,m,x,y,ans;
int read()
{int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
void ST(int n)
{for (int j=1;(1<<j)<=n;j++){for (int i=1;i+(1<<j)-1<=n;i++){xmi[i][j]=min(xmi[i][j-1],xmi[i+(1<<(j-1))][j-1]);ymi[i][j]=min(ymi[i][j-1],ymi[i+(1<<(j-1))][j-1]);xmx[i][j]=max(xmx[i][j-1],xmx[i+(1<<(j-1))][j-1]);ymx[i][j]=max(ymx[i][j-1],ymx[i+(1<<(j-1))][j-1]);}}
}
P RMQ(int l,int r,int t)
{if (l>r){if (t==1||t==3) return P(INF,0);else return P(-INF,0);}int k=0;while ((1<<(k+1))<=r-l+1) k++;if (t==1) return min(xmi[l][k],xmi[r-(1<<k)+1][k]);else if (t==2) return max(xmx[l][k],xmx[r-(1<<k)+1][k]);else if (t==3) return min(ymi[l][k],ymi[r-(1<<k)+1][k]);else if (t==4) return max(ymx[l][k],ymx[r-(1<<k)+1][k]);
}
void does(int x,int y,int pos)
{int dx=max(RMQ(x,pos-1,2).first,RMQ(pos+1,y,2).first)-min(RMQ(x,pos-1,1).first,RMQ(pos+1,y,1).first);int dy=max(RMQ(x,pos-1,4).first,RMQ(pos+1,y,4).first)-min(RMQ(x,pos-1,3).first,RMQ(pos+1,y,3).first);ans=min(ans,max(dx,dy));
}
int main()
{n=read();m=read();for (int i=1;i<=n;i++){scanf("%d%d",&xmi[i][0].first,&ymi[i][0].first);xmi[i][0].second=i; ymi[i][0].second=i;xmx[i][0]=xmi[i][0]; ymx[i][0]=ymi[i][0];}ST(n);while(m--){x=read();y=read();ans=INF;does(x,y,RMQ(x,y,1).second);does(x,y,RMQ(x,y,2).second);does(x,y,RMQ(x,y,3).second);does(x,y,RMQ(x,y,4).second);printf("%d\n",ans);}return 0;
}

View Code

 

转载于:https://www.cnblogs.com/tetew/p/9544812.html

NAIPC2018-K-Zoning Houses相关推荐

  1. NAIPC2018 Zoning Houses(ST表)

    题目描述 Given a registry of all houses in your state or province, you would like to know the minimum si ...

  2. 【ST表】Zoning Houses

    题目描述 Given a registry of all houses in your state or province, you would like to know the minimum si ...

  3. Zoning Houses Kattis 多组记录线段树/ST表

    1.题意:给你n个平面上的点,再给你m个询问,每个询问包括[ l, r ]内的点,让你求出包含这些点在内的最小正方形的边长,你可以忽略这些点内的一个点. 2.分析:如果不忽略点,我们只需要取这些点中的 ...

  4. leetcode 1473. 粉刷房子 III(dp)

    在一个小城市里,有 m 个房子排成一排,你需要给每个房子涂上 n 种颜色之一(颜色编号为 1 到 n ).有的房子去年夏天已经涂过颜色了,所以这些房子不需要被重新涂色. 我们将连续相同颜色尽可能多的房 ...

  5. leetcode--给房子涂色III

     题目是LeetCode第192场周赛的第四题,链接:1473. 给房子涂色 III.具体描述为:在一个小城市里,有m个房子排成一排,你需要给每个房子涂上n种颜色之一(颜色编号为1到n).有的房子去年 ...

  6. GB_T28181-2016.pdf

    国标28181-2016版本检测,由于文件过大,而且博客不支持上传文件,需要GB28181-2016协议文档和公安一所检测文档的可以私信我,QQ:123011785 I C S1 3. 3 1 0 A ...

  7. 【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)

    题干: Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 ...

  8. Python+OpenCV:理解k近邻(kNN)算法(k-Nearest Neighbour (kNN) algorithm)

    Python+OpenCV:理解k近邻(kNN)算法(k-Nearest Neighbour (kNN) algorithm) 理论 kNN is one of the simplest classi ...

  9. CF1146G Zoning Restrictions

    CF1146G Zoning Restrictions 网络流 h<=50? 直接都选择最大的,ans=n*h*h 最小割 考虑舍弃或者罚款 有一个>x就要罚款? 经典取值限制的模型:切糕 ...

最新文章

  1. Ubuntu 11.04解决txt文档中文乱码方法
  2. TAJ齐发力 互联网巨头抢滩“区块链+票据”市场
  3. 1 微信公众号开发 服务器配置 有什么用
  4. DRILLNET 2.0------第十八章 起下钻水力参数计算模型
  5. CentOS 内核升级的总结
  6. Redis基础(十二)——缓存读写策略
  7. 现在五年期定期利率在五以上的银行有哪些?
  8. 如何将 MacBook 的外置屏幕设置为主屏幕
  9. C++ 怎么自己创建头文件
  10. mtk java_MTK,mrp,JAVA你了解多少?
  11. 微博 用户画像_新浪微博的用户画像是怎样构建的?
  12. 幸运九宫格抽奖系统带后台源码
  13. 数据爬虫—全国一般纳税人企业数据采集
  14. 【JS】常用效果总结
  15. 通过Pyecharts绘制可视化地球竟 然如此简单
  16. win10问题:无任何操作,2分钟后电脑就自动休眠
  17. win10笔记本使用ipad作为扩展屏
  18. 建模语言UML在软件开发中的应用
  19. 快排 找第k大的数字
  20. 从程序员角度看心理学中的恐慌区、学习区和舒适区

热门文章

  1. 运动耳机哪种比较好用、最好用的运动耳机
  2. 如何使用Servlet,JSP和MySQL将文件上传到数据库
  3. 品牌国际传播第一步:谁是最重要的人?| 直播活动预告
  4. MFC 图标 icon 如何制作?
  5. 【Android+Kotlin】自适应CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout与Palette
  6. mysql误删数据恢复操作
  7. 【转】操作系统Unix、Windows、Mac OS、Linux的故事
  8. Pandas读取数据
  9. arcgis 同名图层合并_【求助】ArcGIS中怎样合并图层 - 地学 - 小木虫 - 学术 科研 互动社区...
  10. 俞敏洪致青春三“想”:理想、梦想和思想(转载)