Code Chef DARTSEGM(计算几何+凸包)
题面
题解
好眼熟丫……
一月月赛最后一题……,代码都不用改……
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define ll long long
#define pb push_back
#define IT vector<pair<node,int> >::iterator
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R ll x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=200005,S=15,L=15005;
struct node{
int x,y;
inline node(){}
inline node(R int xx,R int yy):x(xx),y(yy){}
inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
inline ll operator *(const node &b)const{return 1ll*x*b.y-1ll*y*b.x;}
inline bool operator <(const node &b)const{return x<b.x||x==b.x&&y<b.y;}
inline ll norm(){return 1ll*x*x+1ll*y*y;}
}p[N];
struct Convex{
vector<node>up,dw;
inline Convex(){}
inline Convex(const vector<node> &b){up=b,dw=b,build();}
Convex operator +(const Convex &b)const{
Convex c;
c.up.resize(up.size()+b.up.size());
merge(up.begin(),up.end(),b.up.begin(),b.up.end(),c.up.begin());
c.dw.resize(dw.size()+b.dw.size());
merge(dw.begin(),dw.end(),b.dw.begin(),b.dw.end(),c.dw.begin());
c.build();
return c;
}
void build(){
int n=up.size(),m=0;
fp(i,0,n-1){
while(m>1&&(up[i]-up[m-2])*(up[m-1]-up[m-2])<=0)--m;
up[m++]=up[i];
}
up.resize(m);
n=dw.size(),m=0;
fp(i,0,n-1){
while(m>1&&(dw[i]-dw[m-2])*(dw[m-1]-dw[m-2])>=0)--m;
dw[m++]=dw[i];
}
dw.resize(m);
}
ll solve(){
vector<node>st=dw;
fd(i,up.size()-2,0)st.pb(up[i]);
int n=st.size()-1;ll res=0;
for(R int i=0,j=1;i<n;++i){
while((st[j+1]-st[i]).norm()>(st[j]-st[i]).norm())j=(j+1)%n;
cmax(res,(st[j]-st[i]).norm()),cmax(res,(st[j+1]-st[i+1]).norm());
}
return res;
}
}st[L][17];
int n,m,Log[L],rt[N];vector<pair<node,int> >c[L];
Convex rmq(int l,int r){
if(l>r)return Convex();
int k=Log[r-l+1];
return st[l][k]+st[r-(1<<k)+1][k];
}
int main(){
// freopen("testdata.in","r",stdin);
// freopen("testdata.out","w",stdout);
n=read(),m=(n-1)/S+1;
fp(i,1,n)p[i].x=read(),p[i].y=read(),rt[i]=(i-1)/S+1;
fp(i,1,m){
int l=(i-1)*S+1,r=min(n,i*S);
fp(j,l,r)c[i].pb(make_pair(p[j],j));
sort(c[i].begin(),c[i].end());
vector<node>point;
for(IT it=c[i].begin();it!=c[i].end();++it)point.pb(it->fi);
st[i][0]=Convex(point);
}
fp(i,2,m)Log[i]=Log[i>>1]+1;
fp(j,1,Log[m])fp(i,1,m-(1<<j)+1)st[i][j]=st[i][j-1]+st[i+(1<<(j-1))][j-1];
int q=read(),l,r;
while(q--){
l=read(),r=read();
if(rt[l]==rt[r]){
vector<node>point;
for(IT it=c[rt[l]].begin();it!=c[rt[l]].end();++it)
if(it->se>=l&&it->se<=r)point.pb(it->fi);
Convex res(point);
print(res.solve());
}else{
vector<node>pointl,pointr;
for(IT it=c[rt[l]].begin();it!=c[rt[l]].end();++it)
if(it->se>=l&&it->se<=r)pointl.pb(it->fi);
for(IT it=c[rt[r]].begin();it!=c[rt[r]].end();++it)
if(it->se>=l&&it->se<=r)pointr.pb(it->fi);
Convex res=rmq(rt[l]+1,rt[r]-1)+Convex(pointl)+Convex(pointr);
print(res.solve());
}
}
return Ot(),0;
}
Code Chef DARTSEGM(计算几何+凸包)的更多相关文章
- Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)
题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...
- Code Chef TSUM2(动态凸包+点分治)
题面 传送门 题解 真是毒瘤随机化算法居然一分都不给 首先这种树上的题目一般想到的都是点分 我们考虑如何统计经过当前点的路径的贡献,设当前点\(u\)在序列中是第\(c\)个,那么一条路径的贡献就是 ...
- Code Chef MINPOLY(计算几何+dp)
题面 传送门 题解 我们枚举这个凸多边形\(y\)坐标最小的点\(p_i\),然后对于所有\(y\)坐标大于等于它的点极角排序 我们预处理出\(s_{j,k}\)表示三角形\(p_i,p_j,p_k\ ...
- Code Chef IMPO(计算几何+扫描线+积分)
题面 传送门 前置芝士 扫描线,积分求面积 题解 我怎么老是忘了积分可以求面积-- 首先,这两个投影的最小的\(x\)坐标和最大的\(x\)坐标必须相等,否则肯定无解 我们考虑一种方法,枚举\(x\) ...
- 【BZOJ-1069】最大土地面积 计算几何 + 凸包 + 旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2707 Solved: 1053[Submit][Sta ...
- 计算几何---凸包问题(Graham/Andrew Scan )
概念 凸包(Convex Hull)是一个计算几何(图形学)中的概念.用不严谨的话来讲,给定二维平面上的点集,凸包就是将最外层的点连接起来构成的凸多边型,它能包含点集中所有点的.严谨的定义和相关概念参 ...
- 计算几何-凸包-toleft test
toLeftTest toLeftTest是判断一个点是否在有向直线左侧的算法. 当点s位于向量pq左侧时,toLeftTest返回true.当点s位于向量pq右侧时,toLeftTest返回fals ...
- 计算几何-凸包算法 Python实现与Matlab动画演示
凸包算法是计算几何中的最经典问题之一了.给定一个点集,计算其凸包.凸包是什么就不罗嗦了 本文给出了<计算几何——算法与应用>中一书所列凸包算法的Python实现和Matlab实现,并给出了 ...
- uva 10652 Board Wrapping (计算几何-凸包)
Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The sma ...
随机推荐
- Spring框架的AOP的底层实现
1. Srping框架的AOP技术底层也是采用的代理技术,代理的方式提供了两种 1. 基于JDK的动态代理 * 必须是面向接口的,只有实现了具体接口的类才能生成代理对象 2. 基于CGLIB动态代理 ...
- 【SQL模板】三.插入/更新 数据模板TSQL
---Name: 插入/更新 数据模板.sql ---Purpose: 用于更新 数据库中 历史数据 或 插入 新数据 的脚本模板 ---Author: xx ---Time: 2015-12-18 ...
- Tomcat端口被占用解决方法
端口被绑定,在命令提示符运行wmic process where "Caption='javaw.exe' and CommandLine like '%%bootstrap.jar%%'& ...
- 子类覆写的变量被private隐藏,强制转换方式通过子类访问父类的被覆写变量:
import static java.lang.System.*; public class SuperParent{ public static void main(String[] args){ ...
- 《Ubuntu标准教程》学习总结
第6章 Shell Shell就是一个命令解释器,负责完成用户与内核之间的交互. 目前流行电Shell主要有:Bourne Shell( sh ).Bourne Again Shell( Bash ) ...
- Zookeeper 系列(一)基本概念
Zookeeper 系列(一)基本概念 https://www.cnblogs.com/wuxl360/p/5817471.html 一.分布式协调技术 在给大家介绍 ZooKeeper 之前先来给大 ...
- 详解Windows Service Wrapper(winsw.exe)及应用场景
winsw.exe可以帮助nginx作为windows服务自启动,不需要每次都输入命令,很方便,使用到目前为止这种做法的效果很完美.你得到了 Windows 服务的支持,而且在服务重启时没有遗留孤立的 ...
- 2018.09.20 atcoder 1D Reversi(模拟)
传送门 考虑每次摆石头都会消去最外层的一个连续颜色串. 所以只用统计一下有多少段颜色即可. 代码: #include<bits/stdc++.h> using namespace std; ...
- Django的路由层(1)
https://www.cnblogs.com/yuanchenqi/articles/8876685.html URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为 ...
- Nginx中间件使用心得(二)
一.基础知识补充 1. 历史由来补充: Nginx是俄罗斯第二大网站的开源项目. 淘宝团队发行了 tengine 增加了很多第三方的包. 2.下载相关的主键 (1)nginx下载地址 ...