题目连接: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]的更多相关文章

  1. [CodeForces - 678F] Lena and Queries 线段树维护凸包

    大致题意: 给出三种操作 1.往平面点集中添加一个点 2.删除第i次添加的点 3.给出一个q,询问平面点集中的q*x+y的最大值 首先对于每个询问,可将z=q*x+y转化为y=z-q*x,即过点(x, ...

  2. Codeforces 678F Lena and Queries

    题意: 你有一个点集,有三种操作: 往集合里插入一个点\((x, y)\) 从集合中删除第\(i\)次操作插入的点 对于给出的\(q\),询问点集中\(x \cdot q + y\)的最大值 分析: ...

  3. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  4. [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]

    这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...

  5. [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]

    这题拖了快一周_(:з」∠)_就把这货单独拿出来溜溜吧~ 本文归属:Educational Codeforces Round 3 题目链接:609F - Frogs and mosquitoes 题目 ...

  6. [Educational Round 17][Codeforces 762F. Tree nesting]

    题目连接:678F - Lena and Queries 题目大意:给出两个树\(S,T\),问\(S\)中有多少连通子图与\(T\)同构.\(|S|\leq 1000,|T|\leq 12\) 题解 ...

  7. [Educational Round 10][Codeforces 652F. Ants on a Circle]

    题目连接:652F - Ants on a Circle 题目大意:\(n\)个蚂蚁在一个大小为\(m\)的圆上,每个蚂蚁有他的初始位置及初始面向,每个单位时间蚂蚁会朝着当前面向移动一个单位长度,在遇 ...

  8. [Educational Round 59][Codeforces 1107G. Vasya and Maximum Profit]

    咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\( ...

  9. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

随机推荐

  1. k8s部署etcd数据库集群

    ⒈下载 https://github.com/etcd-io/etcd/releases ⒉解压 tar -zxvf etcd-v3.3.12-linux-amd64.tar.gz ⒊移动可执行文件及 ...

  2. SQL Server 数据库备份和还原

    一.SQL命令 备份BACKUP DATABASE TestDb TO DISK='d:\TestDb.bak'还原RESTORE DATABASE TestDb FROM DISK='d:\Test ...

  3. GIt -- fatal: refusing to merge unrelated histories 问题处理

    今晚碰到这个问题-- fatal: refusing to merge unrelated histories 想了一下,为什么就这样了? 因为我是先本地创建了仓库,并添加了文件,然后再到github ...

  4. java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.

    java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.M ...

  5. 一个 戴尔 dell 笔记本 bios Preparing to begin setup 问题

    昨天帮亲戚安装系统,是一个dell 笔记本,原本想的很简单,但是在修改了bios里的 SATA 模式后,不但系统启动不了,连bios都进不去了,就像一直在检测一个错误的硬件.google了很多,也没有 ...

  6. spring-mvc访问本地html文件

    项目中要用到在线预览word文档,刚开始考虑是要将word转成pdf文件,然后再直接在浏览器打开pdf文档即可, 但是项目部署在Linux下,在网上搜了一下没有找到合适的方法, 后来项目组讨论用POI ...

  7. day20包

    https://www.cnblogs.com/Eva-J/articles/7292109.html 一.模块: 1.什么是模块:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名 ...

  8. 公设基础equals

    1#  覆盖equals方法的通用约定 1.自反性(reflexive) 自己跟自己的比较必须返回true 2.对称性(symmetric) x=y那么y=z 3.传递性(transitive) x= ...

  9. ubuntu18.04使用SPFlashTool提示缺少libpng12.so.0

    Ubuntu libpng12无法安装解决 Ubuntu 14以上就已经不再支持libpng12,然而有些软件又依赖于libpng12(如我要使用的Cisco Packet Tracer).我们可以采 ...

  10. Trie for string LeetCode

    Trie build and search class TrieNode { public: TrieNode * next[]; bool is_word; TrieNode(bool b = fa ...