题面

BZOJ传送门

思路

首先当然是推式子

对于一个询问点$(x_0,y_0$和给定向量$(x_1,y_1)$来说,点积这么表达:

$A=x_0x_1+y_0y_1$

首先肯定是考虑大小关系:$x_0x_1+y_0y_1\geq x_0x_2+y_0y_2$

然后其实会发现这条路走不通

那么还有什么办法呢?我们发现上面的式子里面是有$Ans$存在的

那我们尝试把$Ans$搞进去

$y_1=-\frac{x_0}{y_0}x_1+\frac{A}{y_0}$

诶,半平面出来了= =

实际上,这里相当于是有一条斜率为$\frac{x_0}{y_0}$的过原点的直线,点$(x_1,y_1)$到这条直线的距离就是$\frac{Ans}{y_0}$

那么这样就好做了:当$y_0 > 0$时,我们只要找到给定点集中的上凸包顶端的那个店,就是答案;反之则是下凸包底端的点

再考虑到:题目中是区间询问,有限制,考虑使用线段树

线段树的话有一个问题:不能每次插入一个新的节点就update一次凸包吧?肯定是不行的

但是发现,线段树区间询问的性质决定了,它只会在已经被完整覆盖(也就是目前插入的数量等于区间长度)的点上跑二分询问

那么我们可以只在一个线段树节点的所有覆盖的位置都已经被插入的时候才求出它的上下凸包

这样大大降低了复杂度,变为$O(n\log^2n)$

Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<vector>
#define eps 1e-9
#define ll long long
using namespace std;
inline int read(){
int re=0,flag=1;char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') flag=-1;
ch=getchar();
}
while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
return re*flag;
}
struct node{
ll x,y;
node(ll xx=0,ll yy=0){x=xx;y=yy;}
inline friend bool operator <(const node &a,const node &b){return (a.x==b.x)?(a.y<b.y):(a.x<b.x);}
inline friend node operator -(const node &a,const node &b){return node(a.x-b.x,a.y-b.y);}
inline friend ll operator *(const node &a,const node &b){return a.x*b.y-a.y*b.x;}
inline friend ll operator /(const node &a,const node &b){return a.x*b.x+a.y*b.y;}
};
vector<node>seg[1600010],q1[1600010],q2[1600010];int top1[1600010],top2[1600010],n;
inline void insert(int l,int r,int num,int pos,node p){
seg[num].push_back(p);
int mid=(l+r)>>1,i;
if(pos==r){//只有完全插入的时候才求凸包
sort(seg[num].begin(),seg[num].end());
int &t1=(top1[num]),&t2=(top2[num]);
for(i=0;i<r-l+1;i++){
while(t1>0&&(q1[num][t1]-q1[num][t1-1])*(q1[num][t1]-seg[num][i])<eps) q1[num].pop_back(),t1--;
q1[num].push_back(seg[num][i]);t1++;
while(t2>0&&(q2[num][t2]-q2[num][t2-1])*(q2[num][t2]-seg[num][i])>-eps) q2[num].pop_back(),t2--;
q2[num].push_back(seg[num][i]);t2++;
}
}
if(l==r) return;
if(mid>=pos) insert(l,mid,num<<1,pos,p);
else insert(mid+1,r,num<<1|1,pos,p);
}
inline ll query1(int l,int r,int ql,int qr,int num,node p){
if(l>=ql&&r<=qr){
int L=1,R=top1[num],MID,ANS=0;
while(L<=R){
MID=(L+R)>>1;
if(q1[num][MID]/p>q1[num][MID-1]/p) ANS=MID,L=MID+1;
else R=MID-1;
}
return q1[num][ANS]/p;
}
int mid=(l+r)>>1;ll re=-1e18;
if(mid>=ql) re=max(re,query1(l,mid,ql,qr,num<<1,p));
if(mid<qr) re=max(re,query1(mid+1,r,ql,qr,num<<1|1,p));
return re;
} inline ll query2(int l,int r,int ql,int qr,int num,node p){
if(l>=ql&&r<=qr){
int L=1,R=top2[num],MID,ANS=0;
while(L<=R){
MID=(L+R)>>1;
if(q2[num][MID]/p>q2[num][MID-1]/p) ANS=MID,L=MID+1;
else R=MID-1;
}
return q2[num][ANS]/p;
}
int mid=(l+r)>>1;ll re=-1e18;
if(mid>=ql) re=max(re,query2(l,mid,ql,qr,num<<1,p));
if(mid<qr) re=max(re,query2(mid+1,r,ql,qr,num<<1|1,p));
return re;
}
int main(){
memset(top1,-1,sizeof(top1));
memset(top2,-1,sizeof(top2));
n=read();int i,cntn=0,t1,t2,t3,t4;ll lastans=0;char op[10],s[10];
scanf("%s",op);
for(i=1;i<=n;i++){
scanf("%s",s);t1=read();t2=read();
if(s[0]=='Q') t3=read(),t4=read();
if(op[0]!='E'){
t1^=(lastans&0x7fffffff);
t2^=(lastans&0x7fffffff);
if(s[0]=='Q'){
t3^=(lastans&0x7fffffff);
t4^=(lastans&0x7fffffff);
}
}
if(s[0]=='Q'){
if(t2>0) lastans=query1(1,n,t3,t4,1,node(t1,t2));
else lastans=query2(1,n,t3,t4,1,node(t1,t2));
printf("%lld\n",lastans);
}
else insert(1,n,1,++cntn,node(t1,t2));
}
}

最新文章

  1. shell选择语句
  2. 关于Mysql错误:./bin/mysqld_safe --user=mysql&amp; [1] 32710 121003 16:40:22 mysqld_safe Logging to &#39;/var/log/mysqld.log&#39;. 121003 16:40:22 mysqld_s
  3. MVVM Command Binding: InvokeCommandAction v.s. EventToCommand
  4. iBeacon知识1
  5. 比较详细PHP生成静态页面教程
  6. loadlibrary DLL 0失败 的一个原因。
  7. BZOJ2310 : ParkII
  8. Delphi的DateToStr StrToDate格式灵活用法
  9. 【转】使用JDK自带jvisualvm监控tomcat
  10. Copying Fields to a new Record
  11. struts2异常记录--java.lang.IllegalStateException
  12. C# 动态绘制任务栏图标的实现
  13. HDU 4287 Intelligent IME hash
  14. C#全屏随机位置显示图片的小程序
  15. android 开源框架推荐
  16. 转:linux运维工程师
  17. Graphical Shell with WebShell - WebOS Internals
  18. EF CodeFirst使用MySql
  19. hive第二篇----hive中partition如何使用
  20. YiShop_最全微信营销涨粉技巧

热门文章

  1. 一个只有十行的精简MVVM框架(上篇)
  2. android分析windowManager、window、viewGroup之间关系(二)
  3. 2019年猪年海报PSD模板-第七部分
  4. hdu1069Monkey and Banana(动态规划)
  5. WEB安全基础之sql注入基础
  6. &lt;cfenv&gt;(fenv.h) _c++11
  7. LeetCode 141——环形链表
  8. linux 文件已经删除,但是空间没有释放的原因
  9. 用命令从mysql中导出/导入表结构及数据
  10. 2.重新安装CM服务