CF187D BRT Contract
考虑如果哪次经过了红灯则显然已经和出发的时间没关系了。
然后我们需要做的是怎么样找到最近的一个是红灯的点。
然后实际下是我们做一个前缀和:\(L_i = \sum d_i\)
然后求\(\min (L_y - L_i) \mod (g + r) > g\)
然后在值域上动态开点线段树,区间查询\(min\)即可。
倒过来处理一下。
//code by fhq_treap
#include<iostream>
#include<cstdio>
#define ll long long
#define N 100005
int n,g,r;
int mod;
ll d[N],f[N];
struct P{
int L,R;
ll mn;
P(){mn = 1e18;}
}T[N * 60];
int cnt;
#define mid ((l + r) >> 1)
#define ls(x) T[x].L
#define rs(x) T[x].R
int Root;
inline void up(int u){T[u].mn = std::min(T[ls(u)].mn,T[rs(u)].mn);}
inline void change(int &u,int l,int r,int p,int v){
if(!u)u = ++cnt;
// std::cout<<u<<" "<<l<<" "<<r<<" "<<p<<" "<<v<<std::endl;
if(l == r){
T[u].mn = v;
return ;
}
if(p <= mid)
change(ls(u),l,mid,p,v);
else
change(rs(u),mid + 1,r,p,v);
up(u);
}
inline ll query(int u,int l,int r,int tl,int tr){
// std::cout<<u<<" "<<l<<" "<<r<<" "<<tl<<" "<<tr<<std::endl;
if(tl > tr)return 1e18;
if(!u)return 1e18;
if(tl <= l && r <= tr)return T[u].mn;
ll ans = 1e18;
if(tl <= mid)ans = std::min(ans,query(ls(u),l,mid,tl,tr));
if(tr > mid)ans = std::min(ans,query(rs(u),mid + 1,r,tl,tr));
return ans;
}
#define root Root,0,mod - 1
int q;
int main(){
scanf("%d%d%d",&n,&g,&r);
mod = g + r;
for(int i = 1;i <= n + 1;++i)
scanf("%lld",&d[i]),d[i] = d[i - 1] + d[i];
for(int i = n;i;-- i){
int t = mod - d[i] % mod;
ll nex = 1e18;
nex = std::min(nex,query(root,std::max(0,g - t),mod - 1 - t));
if(g - t < 0)
nex = std::min(nex,query(root,g - t + mod,mod - 1));
if(nex != 1e18)
f[i] = d[nex] - d[i] + (mod - (d[nex] - d[i]) % mod) + f[nex];
else
f[i] = d[n + 1] - d[i];
change(root,d[i] % mod,i);
}
scanf("%d",&q);
int las = 0;
while(q -- ){
int t;
scanf("%d",&t);
t = t ^ las;
int tt = t % mod;
ll nex = 1e18;
nex = std::min(nex,query(root,std::max(0,g - tt),mod - 1 - tt));
if(g - tt < 0)
nex = std::min(nex,query(root,g - tt + mod,mod - 1));
// std::cout<<nex<<std::endl;
if(nex == 1e18)
std::cout<<t + d[n + 1]<<std::endl,las = (t + d[n + 1]) % 2147483647;
else
std::cout<<d[nex] + (mod - (d[nex] + t) % mod) + f[nex] + t<<std::endl,las = (d[nex] + (mod - (d[nex] + t) % mod) + f[nex] + t) % 2147483647;
}
}
CF187D BRT Contract的更多相关文章
- CF 187D BRT Contract
传送门 给了60分的nq暴力还是很资磁的!!! 基本上想的跟正解差不多了但是刚T2去了就没想细节QAQ 大概就是我们逆序求一下每一个点从0时刻开始走到终点需要用的时间f 我们需要找到它遇到的第一个红灯 ...
- WCF学习之旅—基于Fault Contract 的异常处理(十八)
WCF学习之旅—WCF中传统的异常处理(十六) WCF学习之旅—基于ServiceDebug的异常处理(十七) 三.基于Fault Contract 的异常处理 第二个示例是通过定制Servic ...
- 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图
[源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...
- java-collections.sort异常Comparison method violates its general contract!
转载:http://www.tuicool.com/articles/MZreyuv 异常信息 java.lang.IllegalArgumentException: Comparison metho ...
- JDK7的Comparison method violates its general contract异常
1.摘要 前一阵遇到了一个使用Collections.sort()时报异常的问题,跟小伙伴@zhuidawugui 一起排查了一下,发现问题的原因是JDK7的排序实现改为了TimSort,之后我们又进 ...
- 厦门BRT 硬币型非接触式IC卡分析
前几天去厦门玩顺便多买了一张BRT的票 也就是如图所示的这种硬币型非接触式IC卡 回来之后用Proxmark3分析了卡内数据得到如下16进制dump内容 UID.发卡日期时间. 最近好懒 懒得写了 有 ...
- P6 Enterprise Project Portfolio Contract Management
Find documentation for Primavera products here: Primavera Cloud Services Primavera Prime Primavera P ...
- 重新想象 Windows 8 Store Apps (37) - 契约: Settings Contract
[源码下载] 重新想象 Windows 8 Store Apps (37) - 契约: Settings Contract 作者:webabcd 介绍重新想象 Windows 8 Store Apps ...
- 重新想象 Windows 8 Store Apps (38) - 契约: Search Contract
[源码下载] 重新想象 Windows 8 Store Apps (38) - 契约: Search Contract 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 ...
随机推荐
- 【Java虚拟机7】ClassLoader源码文档翻译
前言 学习JVM类加载器,ClassLoader这个类加载器的核心类是必须要重视的. Notes:下方蓝色文字是自己的翻译(如果有问题请指正).黑色文字是源文档.红色文字是自己的备注. ClassLo ...
- 【UE4 设计模式】设计模式一些概念
定义 设计模式是一套被反复使用的.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用设计模式是为了重用代码.让代码更容易被他人理解.保证代码可靠性. 四人帮 GOF ( Gang of Four ...
- vue3.x组件间通信,实用小技巧都在这里
本想简单写写,没想到说清楚已经变成了一篇很长的帖子,欢迎当笔记搜藏起来. props / emits 父子组件通信 props一般负责向子组件传递数据 下面是一个简单的例子,父组件向子组件传递了一个t ...
- [no_code][Alpha]事后分析
$( "#cnblogs_post_body" ).catalog() 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们要解决的 ...
- STM32单片机的学习方法(方法大体适用所有开发版入门)
1,一款实用的开发板. 这个是实验的基础,有时候软件仿真通过了,在板上并不一定能跑起来,而且有个开发板在手,什么东西都可以直观的看到,效果不是仿真能比的.但开发板不宜多,多了的话连自己都不知道该学哪个 ...
- 最长子序列(线性DP)学习笔记
子序列和子串不一样.子串要求必须连续,而子序列不需要连续. 比如说\(\{a_1,a_2\dots a_n\}\),他的子串就是\(\{a_i,a_{i+1},\dots, a_j|1\leq i\l ...
- cf13A Numbers(,,)
题意: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: th ...
- c++ template 实现一个简单的"栈"
一: 实现一个简单的swap 原来我们写swap一定会这样写: 对于int类型的: swap(const int &x,const int &y) { int temp; temp = ...
- 跟着老猫来搞GO,基础进阶
回顾一下上一篇博客,主要是和大家分享了GO语言的基础语法,其中包含变量定义,基本类型,条件语句,循环语句.那本篇呢就开始和大家同步一下GO语言基础的进阶. 函数的定义 上次其实在很多的DEMO中已经写 ...
- Python Excel工具类封装, 给excel表头搞点颜色
封装Excel工具类 我们常用的excel工具类,读有xlrd,写有xlwt.有读有写,新一代库有pandas,openpyxl等等. 大家用法都差不多,今天博主就介绍新手最爱,我也爱的xlrd和xl ...