[Educational Round 13][Codeforces 678F. Lena and Queries]
题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\)
题解:对每个点集内的点\(P(x_0,y_0)\),作过点\(P\)且斜率为\(-q\)的直线\(l\),则有\(l:y-y_0=-q(x-x_0)\),可以发现当\(x=0\)时,有\(y=q\cdot x_0+y_0\)。因此只要找到一个点,使得过此点作斜率为\(-q\)的直线在\(y\)轴上的截距最大即可。可以发现满足条件的点一定在一个上凸壳上,所以可以用三分来解决问题
但由于需要处理点的插入和删除操作,直接在线求解比较麻烦,所以考虑离线处理询问
因此我们只要记录每一个点的存在时间段,对时间建线段树,对线段树上的每一个节点暴力求出答案即可。由于每一个插入的点只会影响到\(log\ n\)个节点,所以总复杂度是\(O(nlog^2n)\)的
#include<bits/stdc++.h>
using namespace std;
#define N 300005
#define LL long long
struct Point
{
LL x,y;
Point operator -(const Point &t)const{return{x-t.x,y-t.y};}
LL operator *(const Point &t)const{return x*t.y-y*t.x;}
bool operator <(const Point &t)const{return x==t.x?y<t.y:x<t.x;}
}st[N];
LL n,cnt,o[N],q[N],f[N],c[N],r[N],x[N],y[N];
struct Segment_Tree
{
struct rua
{
LL l,r;
set<Point>s;
}t[N<<];
void Build(LL l,LL r,LL x)
{
t[x].l=l,t[x].r=r;
if(l==r)return;
LL mid=l+r>>;
Build(l,mid,x*);
Build(mid+,r,x*+);
}
void change(LL L,LL R,Point p,LL x)
{
LL l=t[x].l,r=t[x].r;
LL mid=l+r>>;
if(L<=l && r<=R){t[x].s.insert(p);return;}
if(L<=mid)change(L,R,p,x*);
if(mid<R)change(L,R,p,x*+);
}
void ask(LL x)
{
LL l=,r=cnt;
while(l+<r)
{
LL mid1=(*l+r)/;
LL mid2=(l+*r)/;
if(q[x]*st[mid1].x+st[mid1].y<q[x]*st[mid2].x+st[mid2].y)l=mid1;
else r=mid2;
}
for(LL i=l;i<=r;i++)f[x]=max(f[x],q[x]*st[i].x+st[i].y);
}
void get(LL x)
{
if(t[x].l<t[x].r)
{
get(x*);
get(x*+);
}
cnt=;
for(auto p:t[x].s)
{
while(cnt> && (st[cnt]-st[cnt-])*(p-st[cnt])>=)cnt--;
st[++cnt]=p;
}
for(LL i=t[x].l;i<=t[x].r;i++)
if(o[i]== && c[i])ask(i);
}
}T;
int main()
{
scanf("%I64d",&n);
T.Build(,n,);
for(LL i=;i<=n;i++)
{
scanf("%I64d",&o[i]);
if(o[i]==)
{
scanf("%I64d%I64d",&x[i],&y[i]);
r[i]=n,cnt++;
}
if(o[i]==)
{
scanf("%I64d",&q[i]);
r[q[i]]=i,cnt--;
}
if(o[i]==)
{
scanf("%I64d",&q[i]),f[i]=-(5e18);
}
c[i]=cnt;
}
for(LL i=;i<=n;i++)
if(o[i]==)T.change(i,r[i],{x[i],y[i]},);
T.get();
for(LL i=;i<=n;i++)
if(o[i]==)
if(c[i])printf("%I64d\n",f[i]);
else printf("EMPTY SET\n");
}
[Educational Round 13][Codeforces 678F. Lena and Queries]的更多相关文章
- [CodeForces - 678F] Lena and Queries 线段树维护凸包
大致题意: 给出三种操作 1.往平面点集中添加一个点 2.删除第i次添加的点 3.给出一个q,询问平面点集中的q*x+y的最大值 首先对于每个询问,可将z=q*x+y转化为y=z-q*x,即过点(x, ...
- Codeforces 678F Lena and Queries
题意: 你有一个点集,有三种操作: 往集合里插入一个点\((x, y)\) 从集合中删除第\(i\)次操作插入的点 对于给出的\(q\),询问点集中\(x \cdot q + y\)的最大值 分析: ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]
这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...
- [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]
这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~ 本文归属:Educational Codeforces Round 3 题目链接:609F - Frogs and mosquitoes 题目 ...
- [Educational Round 17][Codeforces 762F. Tree nesting]
题目连接:678F - Lena and Queries 题目大意:给出两个树\(S,T\),问\(S\)中有多少连通子图与\(T\)同构.\(|S|\leq 1000,|T|\leq 12\) 题解 ...
- [Educational Round 10][Codeforces 652F. Ants on a Circle]
题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...
- [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]
咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
随机推荐
- python3随机数函数
随机数函数 choice(seq) 从序列的元素中随机挑选一个元素,比如random.choice(range(10)),从0到9中随机挑选一个整数. randrange ([start,] stop ...
- [转] word2vec
from: https://www.cnblogs.com/peghoty/p/3857839.html 另附一个比较好的介绍:https://zhuanlan.zhihu.com/p/2630679 ...
- Django-F,Q查询,Templatetags,session,中间件
内容总览1.ORM的多对多的使用 1>语法与实例 2>聚合与分组 3>F与Q查询 4>事务2.模板之自定义 1>初始化 2>filter 3>si ...
- Mysql 时间差(年、月、天、时、分、秒)
SELECT TIME_TO_SEC(TIMEDIFF('2018-09-30 19:38:45', '2018-08-23 10:13:01')) AS DIFF_SECOND1, -- 秒 UNI ...
- C++入门篇十二
成员变量和成员属性: 静态成员函数和静态成员变量是不属于对象的,所以不占有空间,非静态成员是属于对象的,占有存储空间,空类大小1 #include "pch.h" #include ...
- .Net ABP 框架 service 无法访问
最近在看ABP框架,按照文档写好service后,怎么也访问不到,后来发现,忘记把service类设置为public的了! 不写public ABP框架就不能将这个service映射为controll ...
- ios设置音乐audio自动播放
因为audio标签的自动播放:autoplay.在ios系统中不能自动播放,此时需要设置,在进入页面自动播放音乐. 第一步,先引入js微信 <script src="js/jweixi ...
- 关于在eclipse中添加windowbuilder插件的问题
最近在学习GUI,发现我的Eclipse中没有windowbuilder插件,之后按照百度搜索,按照网上教程,去安装时,发现下载网页已经更新,造成了很多问题, 不过问题不大,我已经找到了解决方法: 安 ...
- 启动Eclipse发生错误:An internal error occurred during: "Initializing Java Tooling".
问题描述 由于上一次关闭 Eclipse 时没有正常关闭,再次启动 Eclipse 时报错:An internal error occurred during: "Initializin ...
- Kali Linux的vi编辑器/vim编辑器使用方法
转载声明:本文为转载文章 原文地址:https://www.52host.cn/blog/kali-linux-vi-editor/ Kali Linux系统的vi编辑器/vim编辑器的使用和Cent ...