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 ...
随机推荐
- libCurl 初步认识 - cur easy
cur easy接口简洁明了,主接口4个,辅接口5个. 主接口 初始化 + 配参数 + 执行 + 销毁 初始化 CURL* curl_easy_init() 获得CURL句柄,返回值需要判空. 配参数 ...
- JUnit initializationError错误
一.JUnit Test 测试 initializationError错误 MyMaincom.test.sunc.MyMaininitializationError(com.test.sunc.My ...
- Android 中的广播机制
Android 中的广播机制 Android 中的广播,按照广播响应范围,可以分为应用内广播和全局广播.按照广播的接收方式,可以分为标准广播和有序广播. 广播的分类 响应范围 应用内广播:此类广播只能 ...
- A8
组员:陈锦谋 今日内容: PS学习.抠图.图标像素调整 明日计划: 继续小组内安排的任务 困难: 无
- 《IT小小鸟》读后感
我是来自大一的小小鸟,想要飞却没有一对坚硬的臂膀! 看了<IT小小鸟>了解了学长和学姐们的大学经历后开始让我反思我的大学生活.学长和学姐们通过自身的经历来告诉我们,应该怎么样规划好大学生涯 ...
- (十)Jmeter中的Debug Sampler介绍
一.Debug Sampler介绍: 使用Jmeter开发脚本时,难免需要调试,这时可以使用Jmeter的Debug Sampler,它有三个选项:JMeter properties,JMeter v ...
- Java容器深入浅出之Collection与Iterator接口
Java中用于保存对象的容器,除了数组,就是Collection和Map接口下的容器实现类了,包括用于迭代容器中对象的Iterator接口,构成了Java数据结构主体的集合体系.其中包括: 1. Co ...
- 51nod 1821 最优集合(思维+单调队列)
题意:一个集合S的优美值定义为:最大的x,满足对于任意i∈[1,x],都存在一个S的子集S',使得S'中元素之和为i. 给定n个集合,对于每一次询问,指定一个集合S1和一个集合S2,以及一个数k,要求 ...
- KMP算法模板(pascal)
洛谷P3375: program rrr(input,output); var i,j,lena,lenb:longint; a,b:ansistring; next:..]of longint; b ...
- bzoj3477[Usaco2014 Mar]Sabotage
题意 给出一个长为n的正整数序列(n<=1e5),要求选出一个非空前缀和一个非空后缀(这两段不能够加起来组成整个序列),使得这个前缀和后缀中的所有数字一起求平均数的结果最小 分析 最大/最小化平 ...