[CodeForces - 678F] Lena and Queries 线段树维护凸包
大致题意:
给出三种操作
1、往平面点集中添加一个点
2、删除第i次添加的点
3、给出一个q,询问平面点集中的q*x+y的最大值
首先对于每个询问,可将z=q*x+y转化为y=z-q*x,即过点(x,y)的斜率为-q的最大截距,很容易发现这些点只会在上凸包上,只要在
凸包上三分即可。
对于插入和删除操作,对于每个点可求得其“生存周期”,即其存在于[L,R]的时间范围内。对每个点的时间区间建线段树,则每次询问的
答案即为询问所在的区间内凸包上点中的最大值。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 300100
#define eps 1e-5
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
const long long inf=1LL<<;
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point {
ll x,y;
int l,r;
Point(ll x=,ll y=) : x(x),y(y) {}
Point operator - (const Point &a)const{ return Point(x-a.x,y-a.y); }
Point operator + (const Point &a)const{ return Point(x+a.x,y+a.y); }
Point operator * (const double &a)const{ return Point(x*a,y*a); }
Point operator / (const double &a)const{ return Point(x/a,y/a); }
bool operator < (const Point &a)const{ if(x==a.x) return y<a.y;return x<a.x; }
bool operator == (const Point &a)const{ return dcmp(x-a.x)== && dcmp(y-a.y)==; }
void read() { scanf("%lld%lld",&x,&y);}
void out(){cout<<"Bug: "<<x<<" "<<y<<endl;}
};
inline ll Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; }
inline double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y; }
inline double dis(Vector a) { return sqrt(Dot(a,a)); }
Point p[MAXN];
pii q[MAXN];
int mp[MAXN],m,n;
vector<Point>T[MAXN<<];
ll ans[MAXN];
Point ch[MAXN];
int ty[MAXN];
void Insert(int L,int R,Point pp,int l,int r,int rt){
int mid=l+r>>;
// cout<<L<<" "<<R<<" "<<l<<" "<<r<<" "<<rt<<endl;
if(L<=l && r<=R) {T[rt].pb(pp);return ;}
// if(l==r) return ;
if(R<=mid) Insert(L,R,pp,lson);
else if(L>mid) Insert(L,R,pp,rson);
else Insert(L,mid,pp,lson),Insert(mid+,R,pp,rson);
}
ll Query(int x,int now){
int l=,r=m-;
while(l<r-){
int lmid=(l+l+r)/;
int rmid=(l+r+r+)/;
if(x*ch[lmid].x+ch[lmid].y<x*ch[rmid].x+ch[rmid].y) l=lmid;
else r=rmid;
}
For(i,l,r) ans[now]=max(ans[now],x*ch[i].x+ch[i].y);
}
void Down(int l,int r,int rt){
int mid=l+r>>;
if(l<r){
Down(lson);
Down(rson);
}
m=;
for(int i=;i<T[rt].sz;i++){
while(m> && Cross(T[rt][i]-ch[m-],ch[m-]-ch[m-])<=) m--;
ch[m++]=T[rt][i];
}
For(i,l,r){
if(ty[i]==) Query(mp[i],i);
}
}
void solve(){
cin>>n;
met(mp,);
fill(ans,ans+MAXN,-inf);
For(i,,n*) T[i].clear();
met(p,);
int ct=,pt=,now=;
For(i,,n){
scanf("%d",&ty[i]);
if(ty[i]==) p[pt].read(),p[pt].l=i,p[pt].r=n,mp[i]=pt++,now++;
if(ty[i]==) {scanf("%d",&m);p[mp[m]].r=i,now--;}
if(ty[i]==) {scanf("%d",&mp[i]);if(now==) ty[i]=;}
}
sort(p,p+pt);
For(i,,pt-) Insert(p[i].l,p[i].r,p[i],,n,);
Down(,n,);
for(int i=;i<=n;i++){
if(ty[i]==) puts("EMPTY SET");
if(ty[i]==) printf("%lld\n",ans[i]);
}
}
int main(){
// fre("in.txt","r",stdin);
int t=;
while(t--)solve();
return ;
}
[CodeForces - 678F] Lena and Queries 线段树维护凸包的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- BZOJ 3672[NOI2014]购票(树链剖分+线段树维护凸包+斜率优化) + BZOJ 2402 陶陶的难题II (树链剖分+线段树维护凸包+分数规划+斜率优化)
前言 刚开始看着两道题感觉头皮发麻,后来看看题解,发现挺好理解,只是代码有点长. BZOJ 3672[NOI2014]购票 中文题面,题意略: BZOJ 3672[NOI2014]购票 设f(i)f( ...
- [Educational Round 13][Codeforces 678F. Lena and Queries]
题目连接:678F - Lena and Queries 题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\) 题解:对每个点集内的点\(P( ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- bzoj 3533: [Sdoi2014]向量集 线段树维护凸包
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3533 题解: 首先我们把这些向量都平移到原点.这样我们就发现: 对于每次询问所得到的an ...
- Codeforces 997E - Good Subsegments(线段树维护最小值个数+历史最小值个数之和)
Portal 题意: 给出排列 \(p_1,p_2,p_3,\dots,p_n\),定义一个区间 \([l,r]\) 是好的当且仅当 \(p_l,p_{l+1},p_{l+2},\dots,p_r\) ...
- Codeforces 678F Lena and Queries
题意: 你有一个点集,有三种操作: 往集合里插入一个点\((x, y)\) 从集合中删除第\(i\)次操作插入的点 对于给出的\(q\),询问点集中\(x \cdot q + y\)的最大值 分析: ...
- [BZOJ2402]陶陶的难题II(树链剖分+线段树维护凸包+分数规划)
陶陶的难题II 时间限制:40s 空间限制:128MB 题目描述 输入格式 第一行包含一个正整数N,表示树中结点的个数. 第二行包含N个正实数,第i个数表示xi (1<=xi<= ...
- Contest Hunter 模拟赛09 A [线段树维护斜率]
题面 传送门 思路 首先看看我们到底要干什么:有$1e6$次询问,遍历$i$,每次要求一个形如$b_i \ast a_j - a_i \ast b_j$的东西的最大值 考虑如果一个$j$的决策在当前的 ...
随机推荐
- Linux_用户管理&权限管理
2017年1月11日, 星期三 Linux_用户管理&权限管理 1. Linux用户管理&权限管理 终端的概念: tty 查看登录的终端 类型 user group oth ...
- vue 2.0使用笔记
assets被排除在热重载监听目录之外,一些公共样式文件最好不要放在这个目录 webpack默认没有装less-loader,要.vue文件中使用less,需要npm install less les ...
- 计算广告学-多点归因模型(Multi-Touch Attribution Model)
计算广告学中的一个重要的问题是, 如果用户产生了一次转化(conversion, 比如购买, 注册等), 且该用户在转化之前看过大量不同频道(比如搜索, 展示, 社交等等)的广告, 那么我们如何确定是 ...
- ETL testing
https://www.tutorialspoint.com/etl_testing/index.htm querysurge-installer-6.0.5-linux-x64 测试ETL的工具.
- 训练赛第二场G题 ZOJ 2343
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2343 解题报告:首先我假设最后的正确的结果是a[1] , a[2 ...
- HDU 1422 重温世界杯 DP题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1422 解题报告:DP题,要使旅行的城市最多,关键是要选出一个城市作为开始,以这个城市作为开始的城市时, ...
- Codeforces Round #540 (Div. 3)题解
题目链接: https://codeforces.com/contest/1118 A题: 题意: q次查询,给你一个n,要你用1和2来凑出n,1的花费为a,2的花费为b,求花费的最小值. 思路: 我 ...
- ORB_SLAM2 源码阅读 ORB_SLAM2::Initializer::ComputeF21 (OpenCV 细节)
ORB_SLAM2 计算 F21 的代码是这样的. cv::Mat Initializer::ComputeF21(const vector<cv::Point2f> &vP1,c ...
- ASM配置OGG
两种方法:http://blog.sina.com.cn/s/blog_aa84cfe40101lsks.html 使用ACFS配置OGG:http://ylw6006.blog.51cto.com/ ...
- RTSP消息交互过程
c表示客户端,s表示RTSP服务器端 第一步:查询服务器可用方法 1 c---s :OPTION request //查询s有哪些方法可用 s---c:OPTION response //s回应信息的 ...