[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$的决策在当前的 ...
随机推荐
- hbase系列之:独立模式部署hbase
一.概述 在上一篇博文中,我简要介绍了hbase的部分基础概念,如果想初步了解hbase的理论,可以参看上一篇博文 hbase系列之:初识hbase .本博文主要介绍独立模式下部署hbase及hbas ...
- soj1047.Super Snooker(转换思路+二路求和)
Description On one of my many interplanetary travels I landed on a beautiful little planet called Cr ...
- Asp.net 中,在服务端向客户端写脚本的常用方法
在Asp.net 服务端处理脚本,一般都用 ClientScriptManager ,即web窗体服务端的this.ClientScript.该对象比较常用的方法: 1.RegisterArrayDe ...
- C# TreeView 自定义显示checkbox
本项目需要对TreeView进行定制,要求比较简单,主要要求如下: Winform中TreeView控件默认只支持所有级别的CheckBox显示或者不显示,不能控制制定Level的树节点显示 效果如下 ...
- go 数组
数组的定义和 初始化 数组是同一类型的元素集合 ]int //定义⼀个数组 Go中数组下标从0开始,因此长度为n的数组下标范围:[0,n-1] 整数数组中的元素默认初始化为0,字符串数组中的元素默认初 ...
- linux kernel的中断子系统之(三):IRQ number和中断描述符【转】
转自:http://www.wowotech.net/linux_kenrel/interrupt_descriptor.html 一.前言 本文主要围绕IRQ number和中断描述符(interr ...
- aarch64_c2
collectd-5.7.2-5.fc26.aarch64.rpm 2017-06-18 21:17 634K fedora Mirroring Project collectd-amqp-5.7.2 ...
- 003_ElasticSearch详解与优化设计
简介 概念 安装部署 ES安装 数据索引 索引优化 内存优化 1简介 ElasticSearch(简称ES)是一个分布式.Restful的搜索及分析服务器,设计用于分布式计算:能够达到实时搜索,稳定, ...
- 如何同步删除svn管理的package包目录
转:https://blog.csdn.net/shiwodecuo/article/details/51754598 eclipse在实际的开发中,当我们的项目由svn进行管理时,若想删除选中的整个 ...
- python网络编程-optparse
Python 有两个内建的模块用于处理命令行参数: 一个是 getopt,<Deep in python>一书中也有提到,只能简单处理 命令行参数: 另一个是 optparse,它功能强大 ...