题意:

你有一个点集,有三种操作:

  • 往集合里插入一个点\((x, y)\)
  • 从集合中删除第\(i\)次操作插入的点
  • 对于给出的\(q\),询问点集中\(x \cdot q + y\)的最大值

分析:

先不考虑插入删除操作,对于一个给定的点集,如何寻找\(x \cdot q + y\)最大值

这是一个线性规划的问题,只是可行域变成了离散的点。

设\(x \cdot q + y = z\),其中\(z\)是优化目标。

\(y = -q \cdot x + z\),使得经过点\((x, y)\)斜率为\(-q\)的直线的截距最大。

那么作为最优解的点一定在点集的凸包上,所以可以用单调栈求出凸包,然后三分求最大值。

因为每次操作都可能导致点集发生变化,不可能每次都求一遍凸包。

每个节点对应一个生存期\([L, R]\),即在第\(L\)次操作到第\(R\)次操作中点集中有该点。

然后把它插入到一个线段树的区间中,这样线段树的每个点都对应一段操作区间的一个点集。

用这个点集的凸包更新所有这个区间的询问。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; typedef long long LL;
const int maxn = 300000 + 10;
const LL INF = 1LL << 61; struct Point
{
LL x, y; Point(LL x = 0, LL y = 0): x(x), y(y) {} void read() { scanf("%lld%lld", &x, &y); } bool operator < (const Point& t) const {
return x < t.x || (x == t.x && y < t.y);
} Point operator + (const Point& t) const {
return Point(x + t.x, y + t.y);
} Point operator - (const Point& t) const {
return Point(x - t.x, y - t.y);
}
}; LL Cross(const Point& A, const Point& B) {
return A.x * B.y - A.y * B.x;
} LL Dot(const Point& A, const Point& B) {
return A.x * B.x + A.y * B.y;
} int type[maxn], top;
Point p[maxn], S[maxn];
vector<Point> v[maxn * 4];
bool del[maxn], empty[maxn];
LL ans[maxn]; void insert(int o, int L, int R, int qL, int qR, int v) {
if(qL <= L && R <= qR) {
::v[o].push_back(p[v]);
return;
}
int M = (L + R) / 2;
if(qL <= M) insert(o<<1, L, M, qL, qR, v);
if(qR > M) insert(o<<1|1, M+1, R, qL, qR, v);
} void query(int x) {
int L = 1, R = top;
while(R - L >= 3) {
int mid1 = (L * 2 + R) / 3;
int mid2 = (L + R * 2) / 3;
if(Dot(p[x], S[mid1]) < Dot(p[x], S[mid2])) L = mid1;
else R = mid2;
}
for(int i = L; i <= R; i++)
ans[x] = max(ans[x], Dot(p[x], S[i]));
} void solve(int o, int L, int R) {
if(L < R) {
int M = (L + R) / 2;
solve(o<<1, L, M);
solve(o<<1|1, M+1, R);
} sort(v[o].begin(), v[o].end());
top = 0;
for(int i = 0; i < v[o].size(); i++) {
while(top > 1 && Cross(S[top]-S[top-1], v[o][i]-S[top]) >= 0) top--;
S[++top] = v[o][i];
} for(int i = L; i <= R; i++) if(type[i] == 3 && !empty[i])
query(i);
} int main()
{
int n; scanf("%d", &n);
int cnt = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", type + i);
if(type[i] == 1) {
p[i].read();
cnt++;
} else if(type[i] == 2) {
int x; scanf("%d", &x);
del[x] = true;
cnt--;
insert(1, 1, n, x, i, x);
} else {
scanf("%lld", &p[i].x);
p[i].y = 1LL;
if(!cnt) empty[i] = true;
}
} for(int i = 1; i <= n; i++)
if(type[i] == 1 && !del[i])
insert(1, 1, n, i, n, i); for(int i = 1; i <= n; i++) ans[i] = -INF;
solve(1, 1, n); for(int i = 1; i <= n; i++) if(type[i] == 3) {
if(empty[i]) printf("EMPTY SET\n");
else printf("%lld\n", ans[i]);
} return 0;
}

Codeforces 678F Lena and Queries的更多相关文章

  1. [Educational Round 13][Codeforces 678F. Lena and Queries]

    题目连接:678F - Lena and Queries 题目大意:要求对一个点集实现二维点对的插入,删除,以及询问\(q\):求\(max(x\cdot q+y)\) 题解:对每个点集内的点\(P( ...

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

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

  3. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  4. CodeForces - 369E Valera and Queries(树状数组)

    CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...

  5. codeforces 1217E E. Sum Queries? (线段树

    codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...

  6. 【CF 678F】Lena and Queries

    Time Limit: 2000 ms   Memory Limit: 512 MB Description 初始有一个空集合 n个操作 有三种操作,如下: 1 a b 表示向集合中插入二元组(a,b ...

  7. Codeforces 714C. Sonya and Queries Tire树

    C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...

  8. Educational Codeforces Round 2 B. Queries about less or equal elements 水题

    B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforc ...

  9. Educational Codeforces Round 1 B. Queries on a String 暴力

    B. Queries on a String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/59 ...

随机推荐

  1. 七、SSR(服务端渲染)

    使用框架的问题 下载Vue.js 执行Vue.js 生成HTML页面(首屏显示,依赖于vue.js的加载) 以前没有前端框架时,用jsp/php在服务器端进行数据的填充,发送给客户端就是已经填充好的数 ...

  2. 使用HTML5 canvas做地图(1)基础知识

    之前一直想使用HTML5技术全新做一套地图API,可是苦于时间和精力,迟迟未有行动.后来下定决心,利用下班和周末做出一个大体框架出来,现在和网友分享一下自己的整体的一个思路和想法.欢迎大家提出宝贵建议 ...

  3. 使用CMake生成VS2010项目查看OpenCV源代码

    近期项目需要用到OpenCV中的几个函数,但其函数无法全部实现自己需要的功能,故而需要改进部分函数,为安全及效率起见,想参考OpenCV的源码来改进,这样节省时间的同时亦可提供代码的鲁棒性和通用性.那 ...

  4. Cocos2d-x v3.1 核心类Director,Scene,Layer和Sprite(六)

    Cocos2d-x v3.1 核心类Director,Scene,Layer和Sprite(六) Scene就像一个舞台一样在上面会摆放各种的元素,有的是固定的比如说布景,道具都是固定不动的,但有的元 ...

  5. WebUploader实现采集图片的功能

    项目最开始用百度团队的文件上传组件做了个物料照片采集的功能,后来做员工头像采集时竟然不知道怎么使用了. 参照官方Demo: http://fex.baidu.com/webuploader/getti ...

  6. safenet 超级狗 加密狗

    1.CS程序可以工作正常: 2.BS程序,服务器验证狗,IIS设置32位兼容方法1: dog.SetLibPath,设置查找依赖dll路径: 方法2:默认系统目录 C:\Windows\SysWOW6 ...

  7. C++ vector常用法

    在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结. 1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<in ...

  8. OpenGL位图变形问题

    因为初次接触OpenGL,图形学也后悔当初在学校没有认真学,隐约记得教授当时讲过图像变形的问题,而且我的bitmap也是2的N次方:16*16的,在网络上找到的大多都是一句话:“视口的纵横比一般和视景 ...

  9. PHP数组排序方法总结

    随着PHP的快速发展,用它的人越来越多,在PHP数组学习摘录部分了解到最基本的PHP数组的建立和数组元素的显示.需要深入学习下PHP数组的相关操作.首先接触的就是PHP数组排序.降序的排序问题. so ...

  10. c++ bitset 10进制转二进制

    #include <bitset> using namespace std; void main() { int a; cin>>a; cout<<bitset&l ...