题目描述

FJ is going to teach his cows how to play a song. The song consists of N (1 <= N <= 50,000) notes, and the i-th note lasts for B_i (1 <= B_i <= 10,000) beats (thus no song is longer than 500,000,000 beats). The cows will begin playing the song at time 0; thus, they will play note 1 from time 0 through just before time B_1, note 2 from time B_1 through just before time B_1 + B_2, etc.

However, recently the cows have lost interest in the song, as they feel that it is too long and boring. Thus, to make sure his cows are paying attention, he asks them Q (1 <= Q <= 50,000) questions of the form, 'In the interval from time T through just before time T+1, which note should you be playing?' The cows need your help to answer these questions which are supplied as T_i (0 <= T_i <=

end_of_song).

Consider this song with three notes of durations 2, 1, and 3 beats:

Beat:   0    1    2    3    4    5    6    ...
|----|----|----|----|----|----|--- ...
1111111111 : :
22222: :
333333333333333:

Here is a set of five queries along with the resulting answer:

Query Note

2 2

3 3

4 3

0 1

1 1

约翰准备教他的奶牛们弹一首歌.这首歌由N(1<=n<= 50000)个音阶组成,第i个音阶要敲 击Bi<=10000次.奶牛从第0时刻开始弹,因此他从0时刻到Bi-1时刻都是敲第1个音阶, 然后他从B1时刻到B1+B2-1时刻敲第2个音阶,从B1+B2到B1+B2+B3-1时刻敲第3个 音阶……现在有q(i<q<50000)个问题:在时间段区间t,T+1内,奶牛敲的是哪个音阶?

输入输出格式

输入格式:

  • Line 1: Two space-separated integers: N and Q

  • Lines 2..N+1: Line i+1 contains the single integer: B_i

  • Lines N+2..N+Q+1: Line N+i+1 contains a single integer: T_i

输出格式:

  • Lines 1..Q: For each query, print a single integer that is the index of the note that the cows should be playing.

输入输出样例

输入样例#1: 复制

3 5
2
1
3
2
3
4
0
1
输出样例#1: 复制

2
3
3
1
1
思路:二分
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,q;
int l,r,mid;
int b[],num[];
int main(){
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
num[i]=num[i-]+b[i];
}
for(int i=;i<=q;i++){
int x;
scanf("%d",&x);
l=;r=n;
while(l<=r){
mid=(l+r)/;
if(num[mid]<=x) l=mid+;
else r=mid-;
}
cout<<l<<endl;
}
}

洛谷 P2969 [USACO09DEC]音符Music Notes的更多相关文章

  1. [USACO09DEC]音符Music Notes (二分、STL)

    https://www.luogu.org/problem/P2969 题目描述 FJ is going to teach his cows how to play a song. The song ...

  2. 洛谷 P2970 [USACO09DEC]自私的放牧Selfish Grazing

    P2970 [USACO09DEC]自私的放牧Selfish Grazing 题目描述 Each of Farmer John's N (1 <= N <= 50,000) cows li ...

  3. 洛谷P2017 [USACO09DEC]晕牛Dizzy Cows [拓扑排序]

    题目传送门 晕牛Dizzy Cows 题目背景 Hzwer 神犇最近又征服了一个国家,然后接下来却也遇见了一个难题. 题目描述 The cows have taken to racing each o ...

  4. 洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths

    题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...

  5. [洛谷P2048] [NOI2010] 超级钢琴

    洛谷题目链接:[NOI2010]超级钢琴 题目描述 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号 ...

  6. 洛谷 P2614 计算器弹琴

    P2614 计算器弹琴 题目描述 总所周知,计算器可以拿来干很多它本不应该干的事情,比如写作文.(参看洛谷P2549) 小A发现了一个计算器的另一个隐藏功能——弹琴. http://www.bilib ...

  7. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  8. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

  9. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

随机推荐

  1. CSS2.1(布局)

    浏览器内核 Firefox : geckoIE: tirdentSafari: webkitChrome: 一开始使用webkit 后来基于webkit开发了Blinkopera: 一开始使用pres ...

  2. JavaScript笔记(6)

    一.Date Date实例用来处理日期和时间.Date对象基于1970年1月1日(格林威治时间)世界标准时间起经过的毫秒数.常用:new Date();new Date(value);new Date ...

  3. codeforces 140E.New Year Garland

    传送门: 解题思路: 要求相邻两行小球颜色集合不同,并且限制行内小球相邻不同. 由此可得:每行小球排列都是独立与外界的, 所以答案应该是对于所有行的颜色集合分类,在将行内的答案乘到上面. 先考虑如何分 ...

  4. Python基本循环实例Day 1

    输入正确的用户名和密码,显示登陆界面,超过三次输入错误则锁定,定义字符串记得加上单引号,数字可以int定义,while循环和if循环语句后加上:,break不加: print("------ ...

  5. Vue_小练习

    <!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <meta name ...

  6. Hello World (记事本+命令行)

    读完这篇博客.你将对下面几点更有心得: - Java 中的当前路径.类路径等概念 - javac.java 命令的综合使用 - jar 包的创建及引用 创建文件夹准备測试源代码 打包外部依赖 Jar ...

  7. UVA 12508 - Triangles in the Grid(计数问题)

    12508 - Triangles in the Grid 题目链接 题意:给定一个n∗m格子的矩阵,然后给定A,B.问能找到几个面积在A到B之间的三角形. 思路:枚举每一个子矩阵,然后求[0,A]的 ...

  8. 创建maven项目pom.xml出现错误(依赖Missing)

    Maven的依赖问题 在聚合模块时候,发现在父工程目录中的依赖存在一些问题.一开始是${pagehelper.version},后来将版本直接填写相应的版本如图下 依赖添加失败 * 在父工程的jar包 ...

  9. php 内置的 html 格式化/美化tidy函数 -- 让你的HTML更美观

    php 内置的 html 格式化/美化tidy函数 https://github.com/htacg/tidy-html5 # HTML 格式化 function beautify_html($htm ...

  10. vim-插入格式化时间

    最近一直在搞vimrc的配置.其中有一点就是,我想要实现代码快速注释的功能.而这个功能中的一个关键点就是,我要获得系统当前的时间,然后插入到我的注释里面.我知道vimrc支持shell命令,既使用:r ...