设(x,y)为Q的查询点,分类讨论如下:
1、y>0:  最大化a*x+b*y,维护一个上凸壳三分即可

2、y<0:最大化a*x+b*y  维护一个下凸壳三分即可

我们考虑对时间建出一棵线段树

对于每个区间,如果满了就做出两个凸壳

总时间复杂度是O(n*log^2n)

之后我们考虑查询,每个区间最多被分解为log(n)个区间

在每个区间的凸壳上三分最优解即可

至于优化,可以设定一个阈值,当区间长度小于阈值时不用做凸壳,查询时直接暴力就可以了

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long LL;
const int maxn=400010;
const LL oo=1LL<<60;
char s,Q;
int n,cnt,a,b,T,TA,TB;
LL ans; struct Point{
int x,y;
Point(int x=0,int y=0):x(x),y(y){}
}p[maxn],tmp[maxn],now,A[4000010],B[4000010];
typedef Point Vector;
Vector operator -(const Point &A,const Point &B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator +(const Point &A,const Point &B){return Vector(A.x+B.x,A.y+B.y);}
inline LL Dot(const Point &A,const Point &B){return 1LL*A.x*B.x+1LL*A.y*B.y;}
inline LL Cross(const Point &A,const Point &B){return 1LL*A.x*B.y-1LL*A.y*B.x;} struct Seg_Tree{
int L,R;
int AL,AR;
int BL,BR;
}t[maxn<<2]; bool cmp1(const Point &a,const Point &b){
if(a.x==b.x)return a.y>b.y;
return a.x<b.x;
}
bool cmp2(const Point &a,const Point &b){
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
inline void decode(int &x){x=(s=='E'?x:x=x^(ans&0x7fffffff));}
inline void Get(char &ch){
ch=getchar();
while(ch<'!')ch=getchar();
}
inline void read(int &num){
num=0;int f=1;char ch;Get(ch);
if(ch=='-')f=-1,ch=getchar();
while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
num*=f;
}
void build(int o,int L,int R){
t[o].L=L;t[o].R=R;
if(L==R)return;
int mid=(L+R)>>1;
build(o<<1,L,mid);
build(o<<1|1,mid+1,R);
}
void add(int o){
int L=t[o].L,R=t[o].R;
int mid=(L+R)>>1;
if(R==cnt&&R-L>=70){
T=0;
for(int i=L;i<=R;++i)tmp[++T]=p[i];
sort(tmp+1,tmp+T+1,cmp1);
A[++TA]=tmp[1];t[o].AL=TA;
for(int i=2;i<=T;++i){
if(tmp[i].x!=tmp[i-1].x){
while(TA>t[o].AL&&Cross(tmp[i]-A[TA],A[TA]-A[TA-1])<=0)TA--;
A[++TA]=tmp[i];
}
}t[o].AR=TA;
sort(tmp+1,tmp+T+1,cmp2);
B[++TB]=tmp[1];t[o].BL=TB;
for(int i=2;i<=T;++i){
if(tmp[i].x!=tmp[i-1].x){
while(TB>t[o].BL&&Cross(tmp[i]-B[TB],B[TB]-B[TB-1])>=0)TB--;
B[++TB]=tmp[i];
}
}t[o].BR=TB;
}
if(L==R)return;
if(cnt<=mid)add(o<<1);
else add(o<<1|1);
}
LL Get_A(int L,int R){
while(R-L>=3){
int m1=(L+L+R)/3,m2=(R+R+L)/3;
if(Dot(now,A[m1])>Dot(now,A[m2]))R=m2;
else L=m1;
}
LL ans=-oo;
for(int i=L;i<=R;++i)ans=max(ans,Dot(now,A[i]));
return ans;
}
LL Get_B(int L,int R){
while(R-L>=3){
int m1=(L+L+R)/3,m2=(R+R+L)/3;
if(Dot(now,B[m1])>Dot(now,B[m2]))R=m2;
else L=m1;
}
LL ans=-oo;
for(int i=L;i<=R;++i)ans=max(ans,Dot(now,B[i]));
return ans;
}
LL Get_ask(int o){
LL ans=-oo;
int L=t[o].L,R=t[o].R;
int mid=(L+R)>>1;
if(a<=L&&R<=b){
if(R-L<70)for(int i=L;i<=R;++i)ans=max(ans,Dot(now,p[i]));
else if(now.y>0)ans=Get_A(t[o].AL,t[o].AR);
else ans=Get_B(t[o].BL,t[o].BR);
return ans;
}
if(b<=mid)return Get_ask(o<<1);
else if(a>mid)return Get_ask(o<<1|1);
else return max(Get_ask(o<<1),Get_ask(o<<1|1));
} int main(){
read(n);Get(s);build(1,1,n);
for(int i=1;i<=n;++i){
Get(Q);
if(Q=='A'){
++cnt;
read(p[cnt].x);read(p[cnt].y);
decode(p[cnt].x);decode(p[cnt].y);
add(1);
}else{
read(now.x);read(now.y);
decode(now.x);decode(now.y);
read(a);read(b);
decode(a);decode(b);
ans=Get_ask(1);
printf("%lld\n",ans);
}
}return 0;
}

  

BZOJ 3533 sdoi 2014 向量集的更多相关文章

  1. SDOI 2014 向量集

    [SDOI2014]向量集 题目描述 维护一个向量集合,在线支持以下操作: - "A x y (|x|,|y| < =10^8)":加入向量(x,y); - " Q ...

  2. [BZOJ 3530][Sdoi 2014]数数

    阿拉~好像最近总是做到 AC 自动机的题目呢喵~ 题目的算法似乎马上就能猜到的样子…… AC 自动机 + 数位 dp 先暴力转移出 f[i][j] :表示从 AC 自动机上第 j 号节点走 i 步且不 ...

  3. BZOJ 3533: [Sdoi2014]向量集( 线段树 + 三分 )

    答案一定是在凸壳上的(y>0上凸壳, y<0下凸壳). 线段树维护, 至多N次询问, 每次询问影响O(logN)数量级的线段树结点, 每个结点O(logN)暴力建凸壳, 然后O(logN) ...

  4. [BZOJ 3123] [SDOI 2013]森林(可持久化线段树+并查集+启发式合并)

    [BZOJ 3123] [SDOI 2013]森林(可持久化线段树+启发式合并) 题面 给出一个n个节点m条边的森林,每个节点都有一个权值.有两种操作: Q x y k查询点x到点y路径上所有的权值中 ...

  5. 【SDOI2014】向量集

    [SDOI2014]向量集 题目描述 我们分析一波: 假设我们询问\((A,B)\),\(x_i>x_j\)若 \[ A\cdot x_i+B\cdot y_i>A\cdot x_j+B\ ...

  6. 「SDOI2014」向量集 解题报告

    「SDOI2014」向量集 维护一个向量集合,在线支持以下操作: A x y :加入向量 \((x, y)\): Q x y l r:询问第 \(L\) 个到第 \(R\) 个加入的向量与向量 \(( ...

  7. [BZOJ 1879][SDOI 2009]Bill的挑战 题解(状压DP)

    [BZOJ 1879][SDOI 2009]Bill的挑战 Description Solution 1.考虑状压的方式. 方案1:如果我们把每一个字符串压起来,用一个布尔数组表示与每一个字母的匹配关 ...

  8. [BZOJ 2299][HAOI 2011]向量 题解(裴蜀定理)

    [BZOJ 2299][HAOI 2011]向量 Description 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), ...

  9. BZOJ3533 [Sdoi2014]向量集 【线段树 + 凸包 + 三分】

    题目链接 BZOJ3533 题解 我们设询问的向量为\((x_0,y_0)\),参与乘积的向量为\((x,y)\) 则有 \[ \begin{aligned} ans &= x_0x + y_ ...

随机推荐

  1. OpenGL7-3快速绘制(索引方式)

    代码下载#include "CELLWinApp.hpp"#include <gl/GLU.h>#include <assert.h>#include &l ...

  2. javascript 基础API

    Math.random() 取值范围[0,1)  大于等于0小于1,包括0,不包括1 Math.floor() 向下取整  Math.ceil() 向上取整 第一题:一组数的规则如下:1.1.2.3. ...

  3. 手机APP与原生APP设计的区别

    交互上可以按照原生App的设计方式,效果将越来越接近,主要区别在于: 1.设计中要考虑到浏览器地址栏和工具栏的占有空间,和其对App的操作存在一定的影响. 2.暂时不适合调用系统底层接口,更适合web ...

  4. Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

    1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Lim ...

  5. 隐藏win7盘符

    1.隐藏盘符: //新建注册表,隐藏X盘符 int regeditme() { HKEY hkey; DWORD dwLastError= ;//隐藏X盘2^25 J:2^9=512 X:盘符与挂载的 ...

  6. SQL技巧之行列转换

    比如:id     姓名      状态  1      刘德华    12      刘德华    23      周华健    04      吴彦祖    1 在access中,用一条sql查询 ...

  7. 条形码Code128源代码

    public class Code128 { private DataTable m_Code128 = new DataTable(); ; /// <summary> /// 高度 / ...

  8. Microsoft.DirectX.DirectSound学习(一)

    背景:为什么用到这个类库呢?公司要一个要播放音频文件(.wav)的功能,本来想着很ez的事,网上提供的jq插件.本地也有很多播放器,怎么用都行.可当我实现的时候发现大部分网上插件在火狐上不支持.wav ...

  9. IOS离线教程下载与Dash的使用

    都知道,苹果官网的IOS Developer Library是开发者最喜欢用的知识仓库,但由于有时打开它实在太慢了! 但是,我们可以手动下载离线版的!离线的文档,在这里,叫做DocSet,意指文档集合 ...

  10. preventDefault()、stopPropagation()、return false 之间的区别

    “return false”之所以被误用的如此厉害,是因为它看起来像是完成了我们交给它的工作,浏览器不会再将我们重定向到href中的链接,表单也不会被继续提交,但这么做到底有什么不对呢? 可能在你刚开 ...