Description

维护一个向量集合,在线支持以下操作:
"A x y (|x|,|y| < =10^8)":加入向量(x,y);
" Q x y l r (|x|,|y| < =10^8,1 < =L < =R < =T,其中T为已经加入的向量个数)询问第L个到第R个加入的向量与向量(x,y)的点积的最大值。
    集合初始时为空。

Input

输入的第一行包含整数N和字符s,分别表示操作数和数据类别;
    接下来N行,每行一个操作,格式如上所述。
    请注意s≠'E'时,输入中的所有整数都经过了加密。你可以使用以下程序
得到原始输入:
inline int decode (int x long long lastans) {
     return x ^ (lastans & Ox7fffffff);
}
function decode
begin
    其中x为程序读入的数,lastans为之前最后一次询问的答案。在第一次询问之前,lastans=0。

注:向量(x,y)和(z,W)的点积定义为xz+yw。

Output

对每个Q操作,输出一个整数表示答案。

将向量看作平面上的点,线段树维护上、下凸包,在凸包上三分可得到最优解。对线段树的每个区间,当区间内向量都已读入时计算凸包。
#include<cstdio>
#include<algorithm>
typedef long long i64;
char buf[],*ptr=buf,*pmx=buf+;
const i64 inf=1ll<<;
const int N=1e7;
int g(){
if(ptr==pmx)fread(ptr=buf,,,stdin);
return *ptr++;
}
int _(){
int x=,f=,c=g();
while(c<||c>)c=='-'&&(f=-),c=g();
while(c>&&c<)x=x*+c-,c=g();
return x*f;
}
int _c(){
int c=g();
while(c<'A'||c>'Z')c=g();
return c;
}
void maxs(i64&a,i64 b){if(a<b)a=b;}
void maxs(int&a,int b){if(a<b)a=b;}
void mins(int&a,int b){if(a>b)a=b;}
struct pos{
int x,y;
i64 operator()(pos a){
return i64(x)*a.x+i64(y)*a.y;
}
}mem[],*mp=mem;
pos operator-(pos a,pos b){
return (pos){a.x-b.x,a.y-b.y};
}
i64 operator*(pos a,pos b){
return i64(a.x)*b.y-i64(a.y)*b.x;
}
bool operator<(pos a,pos b){
return a.x!=b.x?a.x<b.x:a.y<b.y;
}
struct node{
pos*l,*r;
void init(int x,int y){
l=mp;
*mp++=(pos){x,y};
r=mp;
}
void ins(pos x){
if(mp>l&&mp[-].x==x.x)--mp;
while(mp-l>=&&(x-mp[-])*(mp[-]-mp[-])>=)--mp;
*mp++=x;
}
void init(node a,node b){
if(!a.l)*this=b;
else if(!b.l)*this=a;
else{
l=mp;
pos*ap=a.l,*bp=b.l;
while(ap!=a.r&&bp!=b.r){
if(*ap<*bp)ins(*ap++);
else ins(*bp++);
}
while(ap!=a.r)ins(*ap++);
while(bp!=b.r)ins(*bp++);
r=mp;
}
}
i64 find(pos x){
if(!l)return -1ll<<;
i64 v1,v2;
int L=,R=r-l-,M1,M2;
while(R-L>){
M1=L+R>>;
M2=M1+;
if(x(l[M1])<x(l[M2]))L=M1;
else R=M2;
}
for(v1=x(l[L++]);L<=R;++L)maxs(v1,x(l[L]));
return v1;
}
}us[],ds[];
bool d[];
int n,de,la=,x,y,l,r,id=;
int main(){
n=_();de=_c()!='E';
for(int i=;i<n;++i){
if(_c()=='A'){
x=_();y=_();++id;
if(de)x^=la,y^=la;
int w=id+;
us[w].init(x,y);
ds[w].init(x,-y);
d[w]=;
for(w>>=;w&&d[w<<^];w>>=){
us[w].init(us[w<<],us[w<<^]);
ds[w].init(ds[w<<],ds[w<<^]);
d[w]=;d[w<<^]=;
}
}else{
x=_();y=_();l=_();r=_();
if(de)x^=la,y^=la,l^=la,r^=la;
i64 ans=-1ll<<;
pos p1=(pos){x,y},p2=(pos){x,-y};
for(l+=,r+=;l^r^;l>>=,r>>=){
if(~l&)maxs(ans,us[l^].find(p1)),maxs(ans,ds[l^].find(p2));
if(r&)maxs(ans,us[r^].find(p1)),maxs(ans,ds[r^].find(p2));
}
printf("%lld\n",ans);
la=ans&0x7fffffff;
}
}
return ;
}

bzoj3533: [Sdoi2014]向量集的更多相关文章

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

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

  2. BZOJ3533:[SDOI2014]向量集(线段树,三分,凸包)

    Description 维护一个向量集合,在线支持以下操作: "A x y (|x|,|y| < =10^8)":加入向量(x,y); " Q x y l r (| ...

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

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

  4. 【bzoj3533】[Sdoi2014]向量集 线段树+STL-vector维护凸包

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

  5. bzoj 3533: [Sdoi2014]向量集 线段树维护凸包

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3533 题解: 首先我们把这些向量都平移到原点.这样我们就发现: 对于每次询问所得到的an ...

  6. bzoj 3533 [Sdoi2014]向量集 线段树+凸包+三分(+动态开数组) 好题

    题目大意 维护一个向量集合,在线支持以下操作: "A x y (|x|,|y| < =10^8)":加入向量(x,y); "Q x y l r (|x|,|y| & ...

  7. Sdoi2014 向量集

    题目描述 题解: 码力太差重构之后才$A……$ 首先求向量点积最大很容易想到凸包, 设已知$(x_0,y_0)$,求$(x,y)$满足$(x,y)*(x_0,y_0)>=(x',y')*(x_0 ...

  8. P3309 [SDOI2014]向量集

    传送门 达成成就:一人独霸三页提交 自己写的莫名其妙MLE死都不知道怎么回事,照着题解打一直RE一个点最后发现竟然是凸包上一个点求错了--四个半小时就一直用来调代码了-- 那么我们只要维护好这个凸壳, ...

  9. SDOI 2014 向量集

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

随机推荐

  1. android 点击edittext弹出软键盘,否则不弹

    只需要加android:windowSoftInputMode="stateHidden|stateAlwaysHidden"就可以 如:<activity android: ...

  2. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  3. 关于Ajax知识点小节

    URL:统一资源定位符 网络的七层协议:网卡 驱动  网络层(ip)  传输层(tcp udp) 会话层( )  应用层(http.) restful表征状态转移(一种表征架构) CURD 增删改查 ...

  4. sgu551 Preparing Problem

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=551 呵呵,题目读的没错,可惜理解错了..== #include <cstdi ...

  5. vimrc配置文件_version1.0_+pathogen, taglist, wordcomplete插件说明

    为了表示对Ruchee的感谢,首先这是Ruchee的个人网站:http://www.ruchee.com/index.html,他的以前很多的代码都放到Git里面了,里面有链接. 看了整整一天,刚开始 ...

  6. Hibernate——property的access属性

    public class Customer implements Serializable { private static final long serialVersionUID = 1L;     ...

  7. LeetCode() Valid Anagram 有问题!!!

    为什么第一个通过,第二个不行呢? class Solution { public: bool isAnagram(string s, string t) { if(s.size() != t.size ...

  8. 记事本写JAVA程序

    编写程序源码: 1.新建记事本程序,修改文件名称为HelloWorld.java 打开编辑以下内容,保存. public class HelloWorld { public static void m ...

  9. printf 格式化输出符号详细说明(转)

    %a             浮点数.十六进制数字和p-记数法(C99)%A 浮点数.十六进制数字和p-记法(C99)%c 一个字符(char) %C           一个ISO宽字符 %d 有符 ...

  10. Android dip(dp) 与 sp的自适应问题

    本文转载于:http://www.oschina.net/question/272860_70761 今天碰到的一个问题,感觉应该其他人也会碰到,拿来分享一下. 我们都知道android在开发配置界面 ...