shallot+向量集 混合版?

首先我们考虑每个向量的存在时间为[L,R]

那么我们知道任意一个区间在线段树上最多被分解成logn个区间

那么我们可以像shallot一样进行区间覆盖

注意到本题的查询是在凸壳上完成的,而凸壳不像shallot的线性基一样有固定的时间复杂度

但是本题的查询是可分离的,那么我们不需要将向量下传,只需要在线段树的每一层做凸壳即可

查询时每走一层对该层三分取最优解,建造凸壳和三分方法同向量集

QAQ 上午因为排序不小心写反了符号调了好久 QAQ

时间复杂度O(nlog^2n)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<vector>
using namespace std; typedef long long LL;
const int maxn=200010;
const LL oo=1LL<<62;
int n,m,f,x,cnt;
int top=0;
int L[maxn],R[maxn];
struct Point{
int x,y;
Point(int x=0,int y=0):x(x),y(y){}
void print(){printf("%d %d\n",x,y);}
}p[maxn],st[4000010],now;
typedef Point Vector;
bool cmp(const Point &A,const Point &B){
if(A.x==B.x)return A.y<B.y;
return A.x<B.x;
}
Vector operator -(const Point &A,const Point &B){return Vector(A.x-B.x,A.y-B.y);}
LL Cross(const Point &A,const Point &B){return 1LL*A.x*B.y-1LL*A.y*B.x;}
LL Dot(const Point &A,const Point &B){return 1LL*A.x*B.x+1LL*A.y*B.y;}
struct ASK{
int x,y,t;
}Q[maxn];
struct Seg_Tree{
vector<Point>V;
int A,B;
void Get_Hull(){
A=top+1;
int sz=V.size();
sort(V.begin(),V.end(),cmp);
for(int i=0;i<sz;++i){
while(top>A&&Cross(V[i]-st[top],st[top]-st[top-1])<=0)top--;
st[++top]=V[i];
}B=top;
}
LL Max(){
if(V.empty())return 0;
if(!A)Get_Hull();
int L=A,R=B;
LL ans=0;
while(R-L>=3){
int m1=(L+L+R)/3,m2=(L+R+R)/3;
if(Dot(st[m1],now)<=Dot(st[m2],now))L=m1;
else R=m2;
}
for(int i=L;i<=R;++i)ans=max(ans,Dot(st[i],now));
return ans;
}
}t[maxn<<2];
void read(int &num){
num=0;char ch=getchar();
while(ch<'!')ch=getchar();
while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
}
void modify(int o,int L,int R,int x,int y,int id){
if(L>=x&&R<=y){
t[o].V.push_back(p[id]);
return;
}
int mid=(L+R)>>1;
if(y<=mid)modify(o<<1,L,mid,x,y,id);
else if(x>mid)modify(o<<1|1,mid+1,R,x,y,id);
else modify(o<<1,L,mid,x,y,id),modify(o<<1|1,mid+1,R,x,y,id);
}
LL ask(int o,int L,int R,int p){
if(L==R)return t[o].Max();
int mid=(L+R)>>1;
if(p<=mid)return max(t[o].Max(),ask(o<<1,L,mid,p));
else return max(t[o].Max(),ask(o<<1|1,mid+1,R,p));
}
int main(){
read(n);
for(int i=1;i<=n;++i){
read(f);
if(f==1){
++cnt;
read(p[cnt].x);read(p[cnt].y);
L[cnt]=i;
}else if(f==2){
read(x);R[x]=i;
}else{
++m;
read(Q[m].x);read(Q[m].y);
Q[m].t=i;
}
}
for(int i=1;i<=cnt;++i){
if(!R[i])R[i]=n;
modify(1,1,n,L[i],R[i],i);
}
for(int i=1;i<=m;++i){
now=Point(Q[i].x,Q[i].y);
printf("%lld\n",ask(1,1,n,Q[i].t));
}
return 0;
}

  

BZOJ 4311 向量的更多相关文章

  1. BZOJ 4311: 向量( 按时间分治 + 线段树 )

    离线, 然后按时间分治, 每个向量都有出现时间[l, r], 直接插入时间线段树(一个向量只会影响O(logN)数量级的线段树节点). 在线段树每个节点弄出凸壳然后二分. 时间复杂度O(Nlog^2N ...

  2. bzoj 4311 向量 时间线建线段树+凸包+三分

    题目大意 你要维护一个向量集合,支持以下操作: 1.插入一个向量(x,y) 2.删除插入的第i个向量 3.查询当前集合与(x,y)点积的最大值是多少.如果当前是空集输出0 分析 按时间线建线段树 大致 ...

  3. 【BZOJ】4311: 向量(线段树分治板子题)

    题解 我们可以根据点积的定义,垂直于原点到给定点构成的直线作一条直线,从正无穷往下平移,第一个碰到的点就是答案 像什么,上凸壳哇 可是--动态维护上凸壳? 我们可以离线,计算每个点能造成贡献的一个询问 ...

  4. BZOJ 3243 向量内积

    Description 两个\(d\)维向量\(A=[a_{1},a_{2},...,a_{d}]\)与\(B=[b_{1},b_{2},...,b_{d}]\)的内积为其相对应维度的权值的乘积和,即 ...

  5. [BZOJ]3243 向量内积(Noi2013)

    小C做了之后很有感觉的题目之一,但因为姿势不对调了很久. Description 两个d 维向量A=[a1,a2,...,ad]与B=[b1,b2,...,bd]的内积为其相对应维度的权值的乘积和,即 ...

  6. BZOJ 2299 向量

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2299 题意:给出一对数a,b,任意使用(a,b), (a,-b), (-a,b), (- ...

  7. BZOJ 2299 向量(裴蜀定理)

    题意:给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), (-b,a), (-b,-a)这些向量,问你能不能拼出另一个向量(x ...

  8. bzoj 4004 向量拟阵

    题解RT. eps = 1e-10 WrongAnswer eps = 1e-5 Accepted /************************************************* ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. @override

    目录 用处 作用 注意   用处: 继承抽象类,必须实现抽象方法,方法上要加@override 实现接口时,必须实现接口里定义的方法,方法上要加@override         作用: 可以检查方法 ...

  2. Poj 2262 / OpenJudge 2262 Goldbach's Conjecture

    1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach ...

  3. TFS遇到TF14446错误的解决方法

    先上图 使用TFS,之前遇到文件被删除直接获取最新版本就行了,今天遇到这个异常:[TF14446: 无法签出“$/****/****/**/Models.pdb”以进行编辑.您的客户端或团队项目配置为 ...

  4. OpenCV3添加滑动条和鼠标事件到图形界面

    鼠标事件和滑动条控制在计算机视觉和OpenCV中非常有用,使用这些控件,用户可以直接与图形界面交互,改变输入图像或者变量的属性值. /* In this section, we are going t ...

  5. javascript实现暂停

    <!DOCTYPE HTML><html> <head>  <title> New Document </title>  <meta ...

  6. memcache的一致性hash算法

    <?php /** * 一致性哈希memcache分布式,采用的是虚拟节点的方式解决分布均匀性问题,查找节点采用二分法快速查找 * the last known user to change t ...

  7. php mysqli多个查询的例子

    php中Mysqli多个查询的例子,感兴趣的朋友可以参考下. php中Mysqli多个查询的例子,感兴趣的朋友可以参考下. mysqli_multi_query(mysqli link,string ...

  8. AngularJS快速开始

    Hello World! 开始学习AngularJS的一个好方法是创建经典应用程序“Hello World!”: 使用您喜爱的文本编辑器,创建一个HTML文件,例如:helloworld.html. ...

  9. JS 判断一个字符串是否包含在一个数组中

    var arr = ["白色", "黑色", "红色", "粉色"]; var sel = "黑色" ...

  10. excle,aspose.cells 公式字段值取不到 xmls转xml

    问题: 一,单元格如果是公式的,读出值为0 aspose.cells 4.4.0.5版本 由于太低,读xmls后缀的excel文件时,发现如果此列是公式算出来的,值是获取不到的.获取到的值一直是0 二 ...