bzoj3938 Robot
3938: Robot
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 336 Solved: 112
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
-20 0 20 100
10 command 1 10
20 command 3 -10
30 query
40 command 1 -30
50 query
Sample Output
280
HINT
Source
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; const ll maxn = ; ll n,m;
ll Tim[maxn],v[maxn],d[maxn],cnt,Time[maxn],ans1,ans2;
bool vis1[maxn << ],vis2[maxn << ]; struct node
{
ll Time,V;
ll opt,pos;
} a[maxn]; struct node2
{
ll k,b;
ll id;
} e1[maxn << ],e2[maxn << ]; double jiao(node2 a,node2 b)
{
return (double)(a.b - b.b) / (b.k - a.k);
} bool cmp(node2 a,node2 b,ll pos)
{
return a.k * pos + a.b < b.k * pos + b.b;
} void update1(int o,int l,int r,int x,int y,node2 a)
{
int mid = (l + r) >> ;
if (x <= l && r <= y)
{
if (!vis1[o])
{
vis1[o] = ;
e1[o] = a;
}
else
{
ll l1 = a.b + a.k * Tim[l],l2 = a.b + a.k * Tim[r];
ll r1 = e1[o].b + e1[o].k * Tim[l],r2 = e1[o].b + e1[o].k * Tim[r];
if (l1 <= r1 && l2 <= r2)
return;
if (l1 >= r1 && l2 >= r2)
e1[o] = a;
else
{
double X = jiao(a,e1[o]);
if (l1 >= r1)
{
if (X <= Tim[mid])
update1(o * ,l,mid,x,y,a);
else
update1(o * + ,mid + ,r,x,y,e1[o]),e1[o] = a;
}
else
{
if (X > Tim[mid])
update1(o * + ,mid + ,r,x,y,a);
else
update1(o * ,l,mid,x,y,e1[o]),e1[o] = a;
}
}
}
return;
}
if (x <= mid)
update1(o * ,l,mid,x,y,a);
if (y > mid)
update1(o * + ,mid + ,r,x,y,a);
} void update2(int o,int l,int r,int x,int y,node2 a)
{
int mid = (l + r) >> ;
if (x <= l && r <= y)
{
if (!vis2[o])
{
vis2[o] = ;
e2[o] = a;
}
else
{
ll l1 = a.b + a.k * Tim[l],l2 = a.b + a.k * Tim[r];
ll r1 = e2[o].b + e2[o].k * Tim[l],r2 = e2[o].b + e2[o].k * Tim[r];
if (l1 >= r1 && l2 >= r2)
return;
if (l1 <= r1 && l2 <= r2)
e2[o] = a;
else
{
double X = jiao(a,e2[o]);
if (l1 <= r1)
{
if (X <= Tim[mid])
update2(o * ,l,mid,x,y,a);
else
update2(o * + ,mid + ,r,x,y,e2[o]),e2[o] = a;
}
else
{
if (X > Tim[mid])
update2(o * + ,mid + ,r,x,y,a);
else
update2(o * ,l,mid,x,y,e2[o]),e2[o] = a;
}
}
}
return;
}
if (x <= mid)
update2(o * ,l,mid,x,y,a);
if (y > mid)
update2(o * + ,mid + ,r,x,y,a);
} node2 query1(ll o,ll l,ll r,ll pos)
{
if (l == r)
return e1[o];
ll mid = (l + r) >> ;
node2 temp;
if (pos <= mid)
temp = query1(o * ,l,mid,pos);
else
temp = query1(o * + ,mid + ,r,pos);
if (cmp(temp,e1[o],Tim[pos]))
return e1[o];
else
return temp;
} node2 query2(ll o,ll l,ll r,ll pos)
{
if (l == r)
return e2[o];
ll mid = (l + r) >> ;
node2 temp;
if (pos <= mid)
temp = query2(o * ,l,mid,pos);
else
temp = query2(o * + ,mid + ,r,pos);
if (cmp(temp,e2[o],Tim[pos]))
return temp;
else
return e2[o];
} int main()
{
scanf("%lld%lld",&n,&m);
for (ll i = ; i <= n; i++)
scanf("%lld",&d[i]);
for (ll i = ; i <= m; i++)
{
scanf("%lld",&Tim[i]);
a[i].Time = Tim[i];
char ch[];
scanf("%s",ch);
if (ch[] == 'c')
{
a[i].opt = ;
scanf("%lld%lld",&a[i].pos,&a[i].V);
}
else
a[i].opt = ;
}
cnt = m + ;
Tim[cnt] = ; //为了插入初始线段,加一个Tim = 0
sort(Tim + ,Tim + + cnt);
cnt = unique(Tim + ,Tim + + cnt) - Tim - ; //去重离散化
for (ll i = ; i <= m; i++)
if (a[i].opt == )
{
ll pos = a[i].pos;
ll l = lower_bound(Tim + ,Tim + + cnt,Time[pos]) - Tim;
ll r = lower_bound(Tim + ,Tim + + cnt,a[i].Time) - Tim;
node2 temp;
temp.k = v[pos]; //线段的斜率和截距
temp.b = d[pos];
update1(,,cnt,l,r,temp);
update2(,,cnt,l,r,temp);
d[pos] += a[i].Time * (v[pos] - a[i].V); //新线段的截距.至于怎么求的,利用两条直线的交点列方程.a[i].Time就是交点横坐标
v[pos] = a[i].V; //v是记录上一次的斜率
Time[pos] = a[i].Time; //记录上一次这个机器人更改的时间
}
for (ll i = ; i <= n; i++)
{
ll l = lower_bound(Tim + ,Tim + + cnt,Time[i]) - Tim;
node2 temp;
temp.k = v[i];
temp.b = d[i];
update1(,,cnt,l,cnt,temp); //最后一条线段变成一条射线,延伸到右端点
update2(,,cnt,l,cnt,temp);
}
for (ll i = ; i <= m; i++)
if (a[i].opt == )
{
ll l = lower_bound(Tim + ,Tim + + cnt,a[i].Time) - Tim;
node2 temp1 = query1(,,cnt,l);
node2 temp2 = query2(,,cnt,l);
ll ans1 = temp1.k * Tim[l] + temp1.b;
ll ans2 = temp2.k * Tim[l] + temp2.b;
printf("%lld\n",max(ans1,-ans2));
} return ;
}
bzoj3938 Robot的更多相关文章
- bzoj千题计划220:bzoj3938: Robot
http://www.lydsy.com/JudgeOnline/problem.php?id=3938 以时间为x轴,以距离为y轴,那么每个机器人的行走路径就是一条折线 把折线分段加入线段树里,然后 ...
- 【bzoj3938】 Robot
http://www.lydsy.com/JudgeOnline/problem.php?id=3938 (题目链接) 题意 给出数轴上$n$个点,有$m$个操作,在时间$t$让一个点以一定的速度移动 ...
- BZOJ3938 & UOJ88:[集训队互测2015]Robot——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3938 http://uoj.ac/problem/88 小q有n只机器人,一开始他把机器人放在了一 ...
- BZOJ3938:Robot
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- [bzoj3938] [Uoj #88] Robot
Description 小 \(q\) 有 \(n\) 只机器人,一开始他把机器人放在了一条数轴上,第 \(i\) 只机器人在 \(a_i\) 的位置上静止,而自己站在原点.在这之后小 \(q\) 会 ...
- Robot Framework用户手册 (版本:3.0)
版权信息:诺基亚网络和解决中心 本翻译尊重原协议,仅用于个人学习使用 1.开始: 1.1 介绍: Robot Framework是一个基于Python的,为终端测试和验收驱动开发(ATDD)的可扩展的 ...
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...
- RIDE -- Robot Framework setup
RobotFramework 是一款基于python 的可以实现关键字驱动和数据驱动并能够生成比较漂亮的测试报告的一款测试框架 这里使用的环境是 python-2.7.10.amd64.msi RID ...
- [8.2] Robot in a Grid
Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can on ...
随机推荐
- 《零基础学JavaScript(全彩版)》学习笔记
<零基础学JavaScript(全彩版)>学习笔记 二〇一九年二月九日星期六0时9分 前期: 刚刚学完<零基础学HTML5+CSS3(全彩版)>,准备开始学习JavaScrip ...
- 排序(C语言实现)
读数据结构与算法分析 插入排序 核心:利用的是从位置0到位置P都是已排序的 所以从位置1开始排序,如果当前位置不对,则和前面元素反复交换重新排序 实现 void InsertionSort(Eleme ...
- 该用哪个:Redis与Memcached之间如何选择呢?
华为云分布式缓存Redis5.0和Memcached都是华为云DCS的核心产品. 那么在不同的使用场景之下,如何选择Redis5.0和Memcached呢? 就由小编为大家进行详细的数据对比分析吧 R ...
- .net core 2.1.3可能引发Could not load file or assembly XXXXX的错误
参考文档: https://github.com/aspnet/Home/issues/3503 写在前面 感觉自己现在干的活离开发越来越远了啊,不过也很好,每天能学到不少东西,中文的,英文的,永远也 ...
- jquery on函数和prop与attr区别
一.jquery on()方法 1.语法 2.例子 $(document).ready(function(){ $("p").on("click",functi ...
- Erlang/Elixir: 使用 OpenCV, Python 搭建图片缩略图服务器
这篇文章是在OSX上测试和运行的的, Ubuntu下的安装和配置请移步到这里 应用程序进程树, 默认 Poolboy 中初始化10个用于处理图片的 Python 工作进程(Worker) 首先安装Op ...
- [linux] reboot和shutdown-r的区别
google看看: 先搜英文的资料 http://askubuntu.com/questions/441969/what-is-the-difference-between-reboot-and-sh ...
- Python:默认参数
Python是个人最喜欢的语言,刚开始接触Python时,总觉得有很多槽点,不太喜欢.后来,不知不觉中,就用的多了.习惯了.喜欢上了.Python的功能真的很强大,自己当初学习这门语言的时候,也记录过 ...
- win10自带中文输入法的用户体验
用户界面: 貌似没有什么界面,不过我感觉这就是最大的优点,没有过度渲染的界面,没有烦人的推送.弹窗,没有定期不定期的更新提示,简洁也是我使用这款输入法的最主要的原因 记住用户的选择: 这点我认为win ...
- Codeforces Round #287 (Div. 2) E. Breaking Good 最短路
题目链接: http://codeforces.com/problemset/problem/507/E E. Breaking Good time limit per test2 secondsme ...