NAIPC2018-K-Zoning Houses
题目描述
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?
输入
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.
输出
样例输入
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的更多相关文章
- 计蒜客 Zoning Houses(线段树区间最大次大)
Given a registry of all houses in your state or province, you would like to know the minimum size of ...
- North American Invitational Programming Contest 2018
A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...
- hdu 2586(LCA在线ST)
How far away ? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): A ...
- hdu4085 Peach Blossom Spring
Peach Blossom Spring http://acm.hdu.edu.cn/showproblem.php?pid=4085 Time Limit: 10000/5000 MS (Java/ ...
- HDOJ 4085 Peach Blossom Spring
discriptionTao Yuanming(365-427) was a Chinese poet of Eastern Jin dynasty. One of his most famous w ...
- django模型操作
Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表
- POJ3928 Pingpong(统计比 K 小的个数 + 树状数组)
Ping pong Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2691 Accepted: 996 Descript ...
- [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 ...
- 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 ...
随机推荐
- Play on Words(欧拉回路)
Description Some of the secret doors contain a very interesting word puzzle. The team of archaeologi ...
- Lucky Conversion(找规律)
Description Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive int ...
- Scrum7
冲刺阶段的总结 一.各个成员今日完成的任务 组员 任务分工 贡献 林泽宇 团队分工.撰写博客.修改完善需求规格说明书.整理代码规范 李涵 后端架构设计 尹海川 logo设计修改.数据库数据 郏敏杰 课 ...
- 20172330 2017-2018-1 《Java程序设计》第十一周学习总结
20172330 2017-2018-1 <程序设计与数据结构>第十一周学习总结 教材学习内容总结 本周的学习内容为集合 Android简介 Android操作系统是一种多用户的Linux ...
- 技术博客HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- HttpWebRequest下载文件,乱码问题解决方案
写在前面 今天之所以会总结HttpWebRequest下载文件,主要是因为在使用该类下载文件的时候,有些地方需要注意一下,在实际的项目中遇到过这种问题,觉得还是有必要总结一下的.在下载文件时,最常见的 ...
- erlang中检查内存泄露
最近项目内存占用过多,检查一下erlang的内存使用情况. 1. 通过etop可以很方便得出erlang内存使用的情况 spawn(fun() -> etop:start([{output, t ...
- Qt多线程-QThreadPool线程池与QRunnable
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt多线程-QThreadPool线程池与QRunnable 本文地址:https:/ ...
- paoding rose controller包及文件名命名规则
1.包命名规则:xxx.xxx.controllers(否则扫描不到)
- shit Rap & mock api
shit Rap & mock api https://thx.github.io/RAP/study.html https://github.com/thx/RAP/wiki/quick_g ...