题意:有一辆火车,初始只有一个车厢,权值为0。有3种操作:

1:在火车头前面加若干辆车

2:在火车车尾加若干辆车

3:每个车的权值加上b + (i - 1) * s,其中i是指这节车厢是从头算的第几个车厢。

每次操作后,询问离火车头最近的权值最小的车厢。

思路:看这篇博客就行了,实现方式比较巧妙。

代码:

#include <bits/stdc++.h>
#define db long long
#define LL long long
using namespace std;
const int maxn = 500010;
const double eps = 1e-9;
int top;
LL b[maxn], s[maxn];
struct point {
db x, y;
point(){};
point(db _x, double _y) :x(_x), y(_y){};
};
point st[maxn];
int n;
LL cal(point x, int now) {
return b[now] - b[x.y] + (x.x - 1) * (s[now] - s[x.y]);
}
LL mul(LL x, LL y, LL x1, LL y1) {
return x * y1 - x1 * y;
}
void add(LL x, LL y) {//x 实际位置 y 读入次序
if(cal(st[top], y) == 0) return;
LL tmp = cal(point(x, y), y);
while(top >= 2) {
if(mul(st[top].x - st[top - 1].x, cal(st[top], y) - cal(st[top - 1], y), x - st[top].x, tmp - cal(st[top], y)) > 0) break;
top--;
}
st[++top] = point(x, y);
}
void del(int x) {
while(top >= 2 && cal(st[top], x) >= cal(st[top - 1], x))
top--;
}
int main() {
int n, m, op;
LL x, y;
scanf("%d%d", &n, &m);
st[++top] = point(1, 0);
for (int i = 1; i <= m; i++) {
b[i] = b[i - 1];
s[i] = s[i - 1];
scanf("%d", &op);
if(op == 1) {
scanf("%lld", &x);
b[i] = s[i] = 0;
st[top = 1] = point(1, i);
n += x;
} else if(op == 2) {
scanf("%lld", &x);
add(n + 1, i);
n += x;
} else {
scanf("%lld%lld", &x, &y);
b[i] += x;
s[i] += y;
del(i);
}
printf("%lld %lld\n", st[top].x, cal(st[top], i));
}
}

  

Codeforces 1137E 凸包的更多相关文章

  1. CodeForces - 605C 凸包+直线与凸包判交

    题目大意: 要完成两种属性p,q的需求,给定n个双属性物品及其单位个物品中含有的属性,要求选择最少的物品来达成属性需求.(可以选择实数个物品) 题解: 实际上是一种属性混合问题 我们知道对于两种双属性 ...

  2. codeforces 70D Professor's task(动态二维凸包)

    题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...

  3. [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)

    题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...

  4. codeforces 70 D. Professor's task 动态凸包

    地址:http://codeforces.com/problemset/problem/70/D 题目: D. Professor's task time limit per test 1 secon ...

  5. [codeforces/gym/101350/L]维护“凸包”

    题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...

  6. Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)

    https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...

  7. Codeforces 166B - Polygon (判断凸包位置关系)

    Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...

  8. CodeForces 166B (凸包)

    求一个多边形是否完全在另一个凸多边形内. 乍一看,好像要判点在多边形内,但复杂度不允许,仔细一想,可以把两个多边形的点混起来求一个共同的凸包,如果共同的凸包依旧是原来凸包上的点,说明是. #inclu ...

  9. Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积

    Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...

随机推荐

  1. I.MX6 support eMMC 5.0

    /***************************************************************************** * I.MX6 support eMMC ...

  2. I.MX6 AR8031 寄存器操作

    /*************************************************************************** * I.MX6 AR8031 寄存器操作 * ...

  3. (四)js数组方法一

    ES5数组方法: Array.prototype.filter()   对数组元素进行过滤 三个参数:元素值,下标,原数组 返回:过滤后符合条件的数组,不会改变原数组 let arr = [2,4,6 ...

  4. 【数据库】SQLite学习

    http://www.cnblogs.com/fnng/archive/2013/05/26/3099547.html

  5. matlab中求逆矩阵的高斯消元法实现的代码

    function qiuni =INV_GET(a)N=length(a);M=eye(N);%得到上三角矩?for i=1:N max=a(i,i); A=i; for j=i+1:N if(abs ...

  6. mybatis-generator的坑

    有天发现mybatis-generator不能用,要加什么根项目前缀, 搞到我重新从github下载,然后发现仓库用不了,原来新项目会改我的maven配置(新坑 后来终于明白要在子项目栏使用手脚架,就 ...

  7. php执行多个存储过程(二)

    使用公共连接文件形式 include_once 'inc/conni.php'; $result = mysqli_query($conni, "call proc_test()" ...

  8. JMeter使用经历

    JMeter是Apache大树下的又一个果实,是一个压力测试工具,因为使用方便又开源免费,也被用来做功能测试.项目里也是拿JMeter来做功能性的接口自动化测试.这里大概说明下怎么用. 首先还是先下载 ...

  9. git的操作

    学习源头: https://www.cnblogs.com/yaoxc/p/3946280.html https://www.cnblogs.com/jeremylee/p/5715289.html ...

  10. 位数问题(dp 递推)

    位数问题 时间限制: 1 Sec  内存限制: 128 MB提交: 35  解决: 19[提交][状态][讨论版][命题人:quanxing] 题目描述 在所有的N位数中,有多少个数中有偶数个数字3? ...