Codeforces Round #200 (Div. 2)344E Read Time(二分)

LLM API调用中的并发与并行:性能、成本与稳定性的工程抉择 并发与并行是分布式系统中优化I/O和计算资源的核心执行模型。并发通过事件循环实现高密度任务调度,擅长掩盖网络等待;并行依托多进程突破GIL限制,专精CPU密集型处理。在LLM API调用场景中,二者并非替代关系,而是针对网络层(高并发有效)、序列化层(高并行有效)和胶水层(需混合编排)的瓶颈特性进行正交优化。真实压测表明,纯asyncio易触发RateLimit错误,而混合执行模式可降低P95延迟62%、减少429错误率超97%,显著提升吞吐与成本效率。本文基于GPT-4-turbo等主流模型的生产实践,解 阅读详情

E. Read Time
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.

When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the i-th reading head is above the track number hi. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered h1, h2, ..., hn have been read at the beginning of the operation.

Mike needs to read the data on m distinct tracks with numbers p1, p2, ..., pm. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.

Input

The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers hi in ascending order (1 ≤ hi ≤ 1010, hi < hi + 1) — the initial positions of the heads. The third line contains m distinct integers pi in ascending order (1 ≤ pi ≤ 1010, pi < pi + 1) - the numbers of tracks to read.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the%I64d specifier.

Output

Print a single number — the minimum time required, in seconds, to read all the needed tracks.

Sample test(s)
input
3 4
2 5 6
1 3 6 8
output
2
input
3 3
1 2 3
1 2 3
output
0
input
1 2
165
142 200
output
81
Note

The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:

  1. during the first second move the 1-st head to the left and let it stay there;
  2. move the second head to the left twice;
  3. move the third head to the right twice (note that the 6-th track has already been read at the beginning).

One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.



有n个磁头,m个位置需要访问,磁头每一秒移动一格,求访问m个磁头需要的最少时间。二分寻找答案。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
int n, m;
ll a[MAXN], b[MAXN];
bool judge(ll x)
{
	int cur = 1;
	ll y;
	for(int i = 1; i <= n; ++i) {
		if(abs(a[i] - b[cur]) > x) continue;
		if(a[i] == b[cur]) cur++;
		if(a[i] > b[cur]) y = max(a[i] + x - 2 * (a[i] - b[cur]), a[i] + (x - (a[i] - b[cur])) / 2);
		else y = a[i] + x;
		while(b[cur] <= y && cur <= m) cur++;
	}
	return cur > m;
}
int main(int argc, char const *argv[])
{
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 1; i <= m; ++i)
		cin >> b[i];
	ll l = -1, r = abs(a[1] - b[1]) * 2 + abs(a[1] - b[m]), mid;
	while(l + 1 < r) {
		mid = (l + r) >> 1;
		if(judge(mid)) r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}


Colab中用PySpark高效读取Kaggle大文件的实战指南 PySpark是一种面向大规模数据处理的分布式计算框架,其核心优势在于内存外(out-of-core)执行、惰性求值和JVM级内存管理,特别适合突破单机内存瓶颈。在资源受限但开箱即用的Google Colab环境中,PySpark可替代pandas处理远超RAM容量的Kaggle数据集(如5–10GB CSV/Parquet),通过合理配置spark.sql.files.maxPartitionBytes与spark.sql.adaptive.enabled等关键参数,实现稳定、可复现、低内存占用的数据加载 阅读详情

相关推荐

OpenCV人脸识别实战:从Haar Cascade检测到LBPH识别全流程解析

人脸识别是计算机视觉领域的经典应用,其核心原理是通过算法提取人脸特征并进行比对。传统方法如Haar Cascade和LBPH(局部二值模式直方图)因其实现简单、计算高效,成为理解底层机制和快速原型开发的理想选择。Haar Cascade利用矩形特征和级联分类器实现快速人脸检测,而LBPH则通过局部纹理描述子构建特征直方图进行识别,两者结合在资源受限场景下具有重要技术价值。在工程实践中,这类方案适用于门禁考勤、桌面应用等小规模封闭集合的识别场景。本文以OpenCV为工具,详细拆解了从环境搭建、数据采集到检测、

weixin_30480075的博客 379

CodeForces - 344E Read Time (模拟题 + 二分法)

CodeForces - 344E Read Time Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Mad scientist Mike does not use slow

qq_18661257的专栏 1559

1、Ovirt 开源虚拟化平台安装

Ovirt虚拟化Node和Engine安装

大鱼 6266

Codeforces 344E - Read Time

二分后贪心#include<bits/stdc++.h> using namespace std; #define LL long long const int maxn = 112345; const LL INFF = 0x3f3f3f3f3f3f3f3fll; LL h[maxn],p[maxn]; int n,m;bool check(LL x){ int pos = 0;

lambda QAQ 352

告别过热焦虑:用Ansys Icepak给你的电子设备做个“水冷体检”(附冷板案例全流程)

本文详细介绍了如何利用Ansys Icepak进行电子设备水冷系统的热仿真分析,帮助工程师解决设备过热问题。通过冷板案例全流程演示,展示了从几何处理、材料设定到求解器设置和后处理的关键步骤,提升散热设计效率与准确性。

weixin_29299807的博客 440

用Zotero+B站Kimi,我如何把一篇顶会论文快速做成组会PPT(含完整提示词)

本文介绍如何利用Zotero和Kimi快速将顶会论文转化为组会PPT,提升学术汇报效率。通过Zotero的文献管理插件和Kimi的AI提炼技术,实现从论文阅读到PPT生成的全流程自动化,帮助研究者在90分钟内完成高质量汇报准备。

weixin_30955617的博客 499

Codeforces 344E Read Time [二分答案]【思维】

题目链接:http://codeforces.com/contest/344/problem/E——————————————–. E. Read Time time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Mad scientis

Tabris的博客 765

从零开始用STM32驱动RGB屏:配置PCLK、DE同步信号的避坑指南

本文详细介绍了如何使用STM32驱动RGB接口LCD屏幕,重点解析了PCLK配置、同步信号极性和DE使能等关键参数的设置方法。通过实战代码示例和常见问题排查指南,帮助开发者避免常见配置错误,实现稳定的显示效果。特别针对800x480 IPS屏提供了优化建议和调试技巧。

sky77的博客 539

codeforces 992E. Nastya and King-Shamans

树状数组 二分 题目传送门 题目大意: 维护一个数列,每次操作为先修改一个数,再询问是否存在一个位置iii满足w[i]=sum[i−1]w[i]=sum[i-1]w[i]=sum[i−1]并输出这个位置。 妙蛙 问题要求出满足 Ax=sumx−1A_x=sum_{x−1}Ax​=sumx−1​ 的位置,这个可以转化为 sumx=2sumx−1sum_x=2sum_{x−1}sumx​=2sumx...

forezxl的博客 484

使用 MATLAB/Simulink 构建一个基于PID控制的直流电机速度调节系统模型

直流电机(DC Motor)因其结构简单、成本低廉、易于控制等特点,广泛应用于各种工业自动化和家用电器中。PID控制器作为最常用的控制策略之一,在直流电机的速度调节系统中具有重要应用价值。通过合理调整比例(P)、积分(I)、微分(D)三个参数,可以实现对电机速度的精确控制。本教程将带你使用构建一个基于PID控制的直流电机速度调节系统模型,涵盖电机模型构建、PID控制器设计、系统仿真与调试等多个方面。本文介绍了如何使用构建一个基于PID控制的直流电机速度调节系统模型。

amy_mhd的博客 217

R语言中的summarise函数和mutate函数用于计算分组占比。下面是关于这两个函数的详细介绍以及相应的源代码示例:

R语言中的summarise函数和mutate函数用于计算分组占比。

CodeByte的博客 1182

CodeForces - 344E Read Time && CodeForces - 830A Office Keys 二分+贪心

题目链接   cf 344e   题意: 有n个磁头,m个位置需要访问,磁头每一秒移动一格,求访问m个磁头需要的最少时间。 思路:   首先老规矩,求最少最多的问题,立马想到二分,对于这个题目,很明显二分时间带入验证可行. 那么问题就转化成了怎么验证?   要想在一定时间内访问多的磁道,那么基于贪心的思想,如果有磁道在当前磁头的左边

Marcus-Bao的个人主页 1435

python爬虫案例——腾讯网新闻标题(异步加载网站数据抓取,post请求)(6)

本篇案例主要讲解异步加载网站如何分析网页接口,以及如何观察post请求URL的参数,网站数据并不难抓取,主要是将要抓取的数据接口分析清楚,才能根据需求编写想要的代码。

@优快云盲敲代码的阿豪的博客 945

Codeforces Round #200 (Div. 1) C. Read Time

Codeforces Round #200 (Div. 1) C. Read Time 题目链接 Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel. When viewed from the side, Mike’s hard drive is an endless

旺崽的博客 2677

万字长文,YOLOv8 yaml 文件解析 | 一文搞定 YOLOv8 分类任务,检测任务,分割任务,关键点任务

YOLOv8 yaml 文件解析 | 一文搞定 YOLOv8 分类任务,检测任务,分割任务,关键点任务

Coding... 1万+

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Codeforces Round #200 (Div. 1)

A Rational Resistance思路:因为每个电阻的电阻是1,这就很好算了,比如要求的电阻是a/b,假设a>b,则要求电阻个数就是a/b + b/(a%b) + (a%b)/(b%(a%b))…,直到某一步的模运算那里能够整除。我也不知道为啥这样,找了俩数据,算了算是这个规律,那就这样算了。#include <bits/stdc++.h> using namespace std; type

梦幻的蔷薇色 618

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #200 (Div. 1) C. Read Time 二分

/** Codeforces Round #200 (Div. 1) C. Read Time 二分 链接:https://codeforces.com/contest/343/problem/C 题意:n个刷子 m个原点 n个刷子同时左右进行刷 问最少的时间使得m个点都能够被刷到; 分析 : 直接二分暴力查找答案 由于刷子存在的点和原点都是递增的 因此每次看枚举的次数看是否能够遍历所有的点...

布呗之路 316

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Codeforces Round #200 (Div. 2) 题解

A. Magnets   题意:给你一列按照顺序的磁铁0代表负极,1代表正极,询问你这些磁铁是几组极性相反的磁铁可以连接在一起变成一组   思路:按照字符串把这些磁铁都读入,然后用一个ans变量记录最后的答案,最少有一组,如果当前的一小块磁铁与上一块不同,ans++,因为他们肯定不能连接在一起,同极排斥,相同就接在一起   代码: #include <bits/stdc++....

weixin_30762087的博客 322

Codeforces Round #200 (Div. 2)E

Read Time 题意:有一个数组,很多指针指在这个数组上,每次每个指针可以向左或向右移动一个位置。给出一些需要访问的位置,问访问用的最少时间。 一个指针只可能转一次方向。二分答案。 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define MAX(...

weixin_34289454的博客 159

Codeforces Round #275 (Div. 1)C(状压+期望)

C. Game with Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You play the game with your friend. The

cq_phqg 1015

codeforces 992

A. Nastya and an Array水题,暴力#include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;string&gt; #include&lt;cmath&gt; #include&lt;cstdlib&gt; #inclu

常胜将军的博客 503

Read Time CodeForces - 343C (二分查找答案)

Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.When viewed from the side, Mike's hard drive is an e...

dsaghjkye的博客 476

Codeforces 344

A: 扫一遍。 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 5 using namespace std; 6 7 int n; 8 9 char s1[3],s2[3]; 10 11 int main() 12 { 13 ...

weixin_30651273的博客 120

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2041

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711
上一篇: Codeforces Round #200 (Div. 2)344D Alternating Current(栈)
下一篇: HDOJ2041 超级楼梯(dp & 打表)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值