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 ...
随机推荐
- python-python爬取妹子图片
# -*- conding=utf-8 -*- import requests from bs4 import BeautifulSoup import io url = "https:// ...
- 413. Reverse Integer【LintCode java】
Description Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-b ...
- phpcms v9如何给父级单页栏目添加内容
对于phpcms单页的调用相信大家都应该没问题,那么如果我们在后台添加的单页有二层甚至更多的时候,这样在管理内容上是没有给父级栏目添加内容这一功能的!那么我们该怎么实现这个功能并调用呢? 首先我们要修 ...
- how to update product listing price sale price and sale date using mobile App
Greetings from Amazon Seller Support, Thank you for writing back to us. I have reviewed our previous ...
- php序列化问题
序列化是将变量转换为可保存或传输的字符串的过程:反序列化就是在适当的时候把这个字符串再转化成原来的变量使用.这两个过程结合起来,可以轻松地存储和传输数据,使程序更具维护性. 1. serialize和 ...
- Scrum立会报告+燃尽图(Beta阶段第二周第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2409 项目地址:https://coding.net/u/wuyy694 ...
- ARP 攻击
场景 A攻击者 192.168.1.3 00:00:00:00:00:01 B受害者 192.168.1.2 00:00:00:00:00:02 C路由器 192.168.1.1 00:00:00:0 ...
- 软工1816 · BETA 版冲刺前准备
任务博客 组长博客 总的来讲Alpha阶段我们计划中的工作是如期完成的.不过由于这样那样的原因,前后端各个任务完成度不算非常高,距离完成一个真正好用.完美的软件还有所差距. 过去存在的问题 测试工作未 ...
- 周总结<5>
周次 学习时间 新编写代码行数 博客量(篇) 学到知识点 12 10 100 1 路由器的设置(ospf协议):网页设计:哈夫曼树(C语言数构) Html案例: <!DOCTYPE html P ...
- MySQL 忘记root密码怎么办
前言:记住如果忘记root密码,在启动MySQL的时候,跳过查询授权表就ok了. 对于RedHat 6 而言 (1)启动mysqld 进程时,为其使用:--skip-grant-tables --sk ...