题意:有一辆火车,初始只有一个车厢,权值为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. LeetCode — (1)

    摘要: Nim Game.WordPattern.Move zeros.First Bad version.Ugly Number五个算法的python实现. 一个月多没更新,大概是因为状态一直不太好 ...

  2. 深入理解java虚拟机-第十章-早期(编译期)优化

    第10章  早期(编译期)优化 javac编译过程: 1.解析与填充符号表过程 词法.语法分析 将源代码的字条流转变为标记(Token)集合.如“int a = b + 2”这名代码包含了6个标记,分 ...

  3. 在oracle里,如何取得本周、本月、本季度、本年度的第一天和最后一天的时间

    在oracle里,如何取得本周.本月.本季度.本年度的第一天和最后一天的时间 --本周 select trunc(sysdate,'d')+1 from dual; select trunc(sysd ...

  4. 中 varStatus的属性简介

    varStatus是<c:forEach>jstl循环标签的一个属性,varStatus属性.就拿varStatus="status"来说,事实上定义了一个status ...

  5. String类的一些常规方法

    String类 String类常用方法: ①length(): length()       长度    方法** 对比:数组.length      属性** 一般情况下,一个数字,一个字母,一个汉 ...

  6. Python函数-repr()

    repr(object) 作用: repr() 函数将对象转化为供解释器读取的形式. object --对象.返回一个对象的 string 格式. 实例: >>>s = 'RUNOO ...

  7. php 两种或的区别 or ||

    php 两种或的区别 or || 实验代码. <?php $p = 999 or 1; var_dump($p); $q = 999 | 1; var_dump($q);

  8. YII框架安装过程-数据库访问

    1.电脑上原来安装了phpstudy.关掉phpstudy,启动wamp,虽启动成功,但仍然无法使用phpmyadmin登录数据库管理页面. 2.查看到系统服务有mysql服务,检查属性均为emsoa ...

  9. 为IIS Host ASP.NET Web Api添加Owin Middleware

    将OWIN App部署在IIS上 要想将Owin App部署在IIS上,只添加Package:Microsoft.OWIN.Host.SystemWeb包即可.它提供了所有Owin配置,Middlew ...

  10. jquery中ajax异步调用接口

    之前写过一个原始的.无封装的页面,没有引入任何外部js,直接实例化Ajax的XmlRequest对象去异步调用接口,参见Ajax异步调用http接口后刷新页面,可对比一下. 现在我们用jquery包装 ...