题目描述

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. Python入门:全站url爬取

    <p>作为一个安全测试人员,面对一个大型网站的时候,手工测试很有可能测试不全,这时候就非常需要一个通用型的网站扫描器.当然能直接扫出漏洞的工具也有很多,但这样你只能算是一个工具使用者,对于 ...

  2. 洛谷 P1885 Moo

    P1885 Moo 题目描述 奶牛Bessie最近在学习字符串操作,它用如下的规则逐一的构造出新的字符串: S(0) = “moo” S(1) = S(0) + “m”+ “ooo” + S(0) = ...

  3. OpenStack_Swift源代码分析——Object-auditor源代码分析(2)

    1 Object-aduitor审计详细分析 上一篇文章中,解说了Object-aduitor的启动,当中审计的详细运行是AuditorWorker实现的.在run_audit中实例化了Auditor ...

  4. Windows下快速安装CACTI流量监控

    Windows下快速安装CACTI流量监控 原文  http://os.51cto.com/art/201111/300977.htm CACTI是一套PHP程序,它利用SNMPGET采集数据,使用R ...

  5. js ---- 函数防抖

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  6. ASP.NET WebAPI RC 竟然不支持最常用的json传参

    壮士断腕(WCF Web API),为的是 ASP.NET Web API 的横空出世,再加上它的开放(开源),于是对之产生了一点点痴情,并写下了HttpClient + ASP.NET Web AP ...

  7. C_深入(内存模型)

    01 数据类型: 为什么有数据类型? 现实生活中的数据太多而且大小形态不一. 数据类型与内存的关系: 数据类型的本质:创建变量的模具,是固定大小的别名. #include "stdio.h& ...

  8. JNDI学习总结(1)——JNDI入门

    JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的意义和作用,就没有 ...

  9. HDU 5063 Operation the Sequence(暴力 数学)

    题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...

  10. apue和unp的学习之旅07——多种边界条件的讨论

    了解一些边界条件,通过观察这些情形,弄清在网络层次发生什么以及它们怎样反映到套接字api,这将很多其它地理解这些层次的工作原理,体会怎样编写应用程序来处理这些情形. //--------------- ...