bzoj3533: [Sdoi2014]向量集
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]向量集的更多相关文章
- BZOJ3533 [Sdoi2014]向量集 【线段树 + 凸包 + 三分】
题目链接 BZOJ3533 题解 我们设询问的向量为\((x_0,y_0)\),参与乘积的向量为\((x,y)\) 则有 \[ \begin{aligned} ans &= x_0x + y_ ...
- BZOJ3533:[SDOI2014]向量集(线段树,三分,凸包)
Description 维护一个向量集合,在线支持以下操作: "A x y (|x|,|y| < =10^8)":加入向量(x,y); " Q x y l r (| ...
- BZOJ 3533: [Sdoi2014]向量集( 线段树 + 三分 )
答案一定是在凸壳上的(y>0上凸壳, y<0下凸壳). 线段树维护, 至多N次询问, 每次询问影响O(logN)数量级的线段树结点, 每个结点O(logN)暴力建凸壳, 然后O(logN) ...
- 【bzoj3533】[Sdoi2014]向量集 线段树+STL-vector维护凸包
题目描述 维护一个向量集合,在线支持以下操作:"A x y (|x|,|y| < =10^8)":加入向量(x,y);"Q x y l r (|x|,|y| < ...
- bzoj 3533: [Sdoi2014]向量集 线段树维护凸包
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3533 题解: 首先我们把这些向量都平移到原点.这样我们就发现: 对于每次询问所得到的an ...
- bzoj 3533 [Sdoi2014]向量集 线段树+凸包+三分(+动态开数组) 好题
题目大意 维护一个向量集合,在线支持以下操作: "A x y (|x|,|y| < =10^8)":加入向量(x,y); "Q x y l r (|x|,|y| & ...
- Sdoi2014 向量集
题目描述 题解: 码力太差重构之后才$A……$ 首先求向量点积最大很容易想到凸包, 设已知$(x_0,y_0)$,求$(x,y)$满足$(x,y)*(x_0,y_0)>=(x',y')*(x_0 ...
- P3309 [SDOI2014]向量集
传送门 达成成就:一人独霸三页提交 自己写的莫名其妙MLE死都不知道怎么回事,照着题解打一直RE一个点最后发现竟然是凸包上一个点求错了--四个半小时就一直用来调代码了-- 那么我们只要维护好这个凸壳, ...
- SDOI 2014 向量集
[SDOI2014]向量集 题目描述 维护一个向量集合,在线支持以下操作: - "A x y (|x|,|y| < =10^8)":加入向量(x,y); - " Q ...
随机推荐
- CentOS6编译装载nbd模块
今天突然发现CentOS系统没有nbd模块,只能重新装下,下面记录下整个编译过程: 系统:CentOS6.5 内核:2.6.32-431.el6.x86_64 [root@localhost ~]# ...
- 1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在loc ...
- ANTLR3完全参考指南读书笔记[07]
前言 真正意义上的程序员都很懒,懒的连多余的一行代码也不写. 如果能将底层满手油污的活儿都可以交给别人去做,自己就扮演个智囊团成员的角色,生活会比想象中的还要惬意. 严格的按照指令执行长时间不知疲倦的 ...
- N Sum
题目:N Sum 描述: Given an array of integers, return indices of the two numbers such that they add up to ...
- 矩阵基本运算的 Python 实现
from...import与import区别在于import直接导入指定的库,而from....import则是从指定的库中导入指定的模块 import...as则是将import A as B,给予 ...
- 【转】Entity Framework技术导游系列开篇与热身
转自:http://blog.csdn.net/bitfan/article/details/12779517 Entity Framework走马观花 之 把握全局 ================ ...
- c#部分---结构体;
结构体:自定义类型 值类型一组变量的组合需要定义的位置 class里面 main函数外面里面包含的变量可以是多种数据类型的 例如学生信息的结构体:学号,姓名,性别,分数 struct Student ...
- C#部分---二维数组、split分割;
二维数组定义方式: int[,] array = new int[3, 4]{ {1,2,3,4}, {3,4,5,6}, {5,6,7,8} }; 3表示,有三个一 ...
- 最小二乘法 java
import java.util.ArrayList; import java.util.Collection; import org.apache.commons.math3.optim.Point ...
- Python学习(1)
幂运算符比取反(一元运算符)的优先级要高. >>>-3**2 -9 >>>(-3)**2 9 >>>pow(2,3) 8 abs函数可以得到数的绝 ...