BZOJ3938:Robot
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=3938
首先,操作的个数小于等于\(6*10^5\),因为这个我对着我的程序干瞪眼白白浪费了半个晚上和半个早上。
另外,由于是求离原点距离最远的,所以应该把所有的线段都移到\(y\)的正半轴上来。
转化题意:对于\(i\)号机器人从第\(x\)秒到第\(y\)秒都按照\(k\)的速度移动,第\(x\)秒在\(st\),第\(y\)秒在\(ed\),我们可以算出一次函数的\(b\),然后在一次函数\(y=kx+b\)上面截取\(x\)到\(y\)丢到李超线段树里去维护。
最后,这题跟BZOJ3165:[HEOI2013]Segment基本一样。
时间复杂度:\(O(nlog^2n)\)
空间复杂度:\(O(n)\)
代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=6e5+5;
int n,m,cnt,tot;
int pos[maxn],nxt[maxn],tim[maxn*4];
int a[maxn],t[maxn],opt[maxn],id[maxn],x[maxn];
int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
}
struct Line {
ll b;
int st,ed,k;
Line() {}
Line(int _st,int _ed,ll _b,int _k) {
st=_st,ed=_ed,b=_b,k=_k;
}
}line[maxn*4];
struct segment_tree {
int tag[maxn<<3];
ll calc(int id,int x) {
return line[id].b+1ll*x*line[id].k;
}
bool check(int id1,int id2,int x) {
return calc(id1,x)<calc(id2,x);
}
ll query(int p,int l,int r,int pos) {
if(l==r)return calc(tag[p],tim[l]);
int mid=(l+r)>>1;ll ans=calc(tag[p],tim[pos]);
if(pos<=mid)ans=max(ans,query(p<<1,l,mid,pos));
else ans=max(ans,query(p<<1|1,mid+1,r,pos));
return ans;
}
void change(int p,int l,int r,int id) {
if(l==r) {
if(check(tag[p],id,tim[l]))tag[p]=id;
return;
}
int mid=(l+r)>>1;
if(line[id].k>line[tag[p]].k) {
if(check(tag[p],id,tim[mid]))change(p<<1,l,mid,tag[p]),tag[p]=id;
else change(p<<1|1,mid+1,r,id);
}
else if(line[id].k==line[tag[p]].k) {
if(check(tag[p],id,tim[mid]))tag[p]=id;
}
else {
if(check(tag[p],id,tim[mid]))change(p<<1|1,mid+1,r,tag[p]),tag[p]=id;
else change(p<<1,l,mid,id);
}
}
void ins(int p,int l,int r,int L,int R,int id) {
if(L<=l&&r<=R) {change(p,l,r,id);return;}
int mid=(l+r)>>1;
if(L<=mid)ins(p<<1,l,mid,L,R,id);
if(R>mid)ins(p<<1|1,mid+1,r,L,R,id);
}
}T;
void make_line(int l,int r,ll B,int K) {
l=t[l],r=t[r];
ll st=B,ed=B+1ll*K*(r-l);B=ed-1ll*r*K;
if(st<=0&&ed<=0)line[++cnt]=Line(l,r,-B,-K);
else if(st>=0&&ed>=0)line[++cnt]=Line(l,r,B,K);
else {
int T=(-B)/K;tim[++tot]=T;
if(st>=0)line[++cnt]=Line(l,T,B,K),line[++cnt]=Line(T+1,r,-B,-K);
else line[++cnt]=Line(l,T,-B,-K),line[++cnt]=Line(T+1,r,B,K);
}
}
void solve_lines() {
for(int i=1;i<=n;i++) {
make_line(1,pos[i],a[i],0);
int now=pos[i];ll B=a[i];
while(now<m) {
make_line(now,nxt[now],B,x[now]);
B=B+1ll*x[now]*(t[nxt[now]]-t[now]);
now=nxt[now];
}
}
}
int main() {
n=read(),tot=m=read();
for(int i=1;i<=n;i++)
a[i]=read(),pos[i]=m;
for(int i=1;i<=m;i++) {
tim[i]=t[i]=read();
char s[20];scanf("%s",s+1);
if(s[1]=='q')opt[i]=1;
else opt[i]=2;
if(opt[i]==2)id[i]=read(),x[i]=read();
}
for(int i=m;i;i--)
if(opt[i]==2)nxt[i]=pos[id[i]],pos[id[i]]=i;
solve_lines();sort(tim+1,tim+tot+1);
int num=unique(tim+1,tim+tot+1)-tim-1;
tot=num;
for(int i=1;i<=cnt;i++) {
int l=lower_bound(tim+1,tim+tot+1,line[i].st)-tim;
int r=lower_bound(tim+1,tim+tot+1,line[i].ed)-tim;
T.ins(1,1,tot,l,r,i);
}
for(int i=1;i<=m;i++)
if(opt[i]==1) {
int q=lower_bound(tim+1,tim+tot+1,t[i])-tim;
printf("%lld\n",T.query(1,1,tot,q));
}
return 0;
}
BZOJ3938:Robot的更多相关文章
- 关于《自动化测试实战宝典:Robot Framework + Python从小工到专家》
受新冠疫情影响,笔者被“困”在湖北老家七十余天,于4月1号(愚人节)这天,终于返回到广州.当前国内疫情基本已趋于平稳,但全球疫情整体势态仍在持续疯涨,累计确诊病例已近80万人.祈祷这场全球性灾难能尽早 ...
- 简单介绍下自动化框架:Robot Framework
一.简介: Robot Framework:Robot Framework是由Python编写的一款功能丰富并且扩展性强的自动化测试框架,也可以在Java和 .NET 上运行. HttpRunner: ...
- RobotFramework-RIDE环境搭建二:Robot Framework-RIDE安装过程以及踩雷点
前期准备工作: Python 2.7(上篇文章中已安装成功) Robot Framework-2.8.5 Robot Framework-RIDE-1.5.2.1 (测试用例的创建.运行可以在图形界面 ...
- SPOJ:Robot(数学期望)
There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a ...
- POJ 1573:Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11324 Accepted: 5512 Des ...
- 一:robot framework环境安装
1.安装robot framework: 打开cmd进入dos下,输入 pip install robotframework Microsoft Windows [版本 10.0.18362.267] ...
- 【bzoj3938】 Robot
http://www.lydsy.com/JudgeOnline/problem.php?id=3938 (题目链接) 题意 给出数轴上$n$个点,有$m$个操作,在时间$t$让一个点以一定的速度移动 ...
- 三:robot framework常用关键字
该部分介绍的是内置库:Builtin,估不需要导入,即可使用 1.RF中定义一个变量: ${XXX} XXX表示:变量名 *** Settings *** *** Test Cases *** 定 ...
- 二:robot framework基本组成
1.RF组成:套件.用例.关键字 套件:测试用例的集合,可以是一个模块的功能点的集合.也可以是很多模块功能点的集合 用例:一般是由多个关键字组成的 关键字:测试库.资源文件.用例所在文件的关键字表 2 ...
随机推荐
- Chrome自带恐龙小游戏的源码研究(完)
在上一篇<Chrome自带恐龙小游戏的源码研究(七)>中研究了恐龙与障碍物的碰撞检测,这一篇主要研究组成游戏的其它要素. 游戏分数记录 如图所示,分数及最高分记录显示在游戏界面的右上角,每 ...
- Getting Started with the G1 Garbage Collector(译)
原文链接:Getting Started with the G1 Garbage Collector 概述 目的 这篇教程包含了G1垃圾收集器使用和它如何与HotSpot JVM配合使用的基本知识.你 ...
- YARN/MRv2 中基本术语介绍
YARN/MRv2是下一代MapReduce框架(见Hadoop-0.23.0),该框架完全不同于当前的MapReduce框架,它在扩展性,容错性和通用性等方面更出色,据统计,Yarn有超过15000 ...
- java 单例模式(转载)
http://www.cnblogs.com/whgw/archive/2011/10/05/2199535.html Java中单例模式是一种常见的设计模式,可分为三种:懒汉式单例.饿汉式单例.登记 ...
- ASP.NET动态网站制作(8)-- JS(3)
前言:JS的第三节课,这节课主要讲函数.对象及方法. 内容: 1.九九乘法表例子: HTML代码: <!DOCTYPE html> <html xmlns="http:// ...
- jquery实现重置
$('#reset').click(function(){ $('#info_frm')[0].reset(); });
- Intellij IDEA创建的Web项目配置Tomcat并启动Maven项目(转)
大部分是直接上图哦. 点击如图所示的地方,进行添加Tomcat配置页面 弹出页面后,按照如图顺序找到,点击+号 tomcat Service -> Local 注意,这里不要选错了哦,还有一个T ...
- 九度OJ 1148:Financial Management(财务管理) (平均数)
与1141题相同. 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:843 解决:502 题目描述: Larry graduated this year and finally has a ...
- 观察OnPaint与OnIdle与OnSize事件
import wx class SketchWindow(wx.Window): def __init__(self, parent, ID): wx.Window.__init__(self, pa ...
- Java for LeetCode 126 Word Ladder II 【HARD】
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...