当前位置:网站首页>[USACO 2009 Dec S]Music Notes
[USACO 2009 Dec S]Music Notes
2022-07-03 04:35:00 【cq. tiancx】
subject : [USACO 2009 Dec S]Music Notes , ha-ha , Let's look at a question with dichotomy today , This is from USACO A question on , Okay , Let's have a look at the meaning of the title :
The title description is copied , There may be some display errors , I'll put the title link below !
Topic link : [USACO 2009 Dec S]Music Notes
Title Description
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 Bi (1 <= Bi <= 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 B1, note 2 from time B1 through just before time B1 + B2, 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 Ti (0 <= Ti <= end_of_song).Input description
- Line 1: Two space-separated integers: N and Q
- Lines 2…N+1: Line i+1 contains the single integer: Bi
- Lines N+2…N+Q+1: Line N+i+1 contains a single integer: Ti
Output description
- Lines 1…Q: Line i of the output contains the result of query i as a single integer.
Example 1
Input
3 5
2
1
3
2
3
4
0
1
Output
2
3
3
1
1
Ideas
:
Adopt the idea of prefix and dichotomy , It will be solved soon
Let's look at success AC The code of :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,q;
int a[1000010];
int sum[1000010];// Storing prefixes and
int main(){
ios::sync_with_stdio(false);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
sum[i]=sum[i-1]+a[i];
}
while(q--){
int x; cin>>x;
int ans=upper_bound(sum+1,sum+n+1,x)-sum;// Minus the starting position here is the subscript of the element
cout<<ans<<"\n";
}
return 0;
}
Thanks for reading
, Because the author level is limited , There are inevitably shortcomings , If the reader finds a problem , Please criticize , Leave a message in the message area or send a private message to inform , I will revise it as soon as possible . If you guys have any good solutions , Or meaningful solutions can be displayed in the comment area , Thank you very much .
Writing is not easy to , I hope all bosses will praise me , Add a focus on !
边栏推荐
- Symbol of array element product of leetcode simple problem
- [literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
- Drf--- quick start 01
- UiPath实战(08) - 选取器(Selector)
- Learning practice: comprehensive application of cycle and branch structure (I)
- 【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
- Prefix and (continuously updated)
- Redraw and reflow
- Youdao cloud notes
- Games101 Lesson 9 shading 3 Notes
猜你喜欢
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
UiPath实战(08) - 选取器(Selector)
[free completion] development of course guidance platform (source code +lunwen)
FISCO bcos zero knowledge proof Fiat Shamir instance source code
Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
Two drawing interfaces - 1 Matlab style interface
The programmer went to bed at 12 o'clock in the middle of the night, and the leader angrily scolded: go to bed so early, you are very good at keeping fit
2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
随机推荐
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
data2vec! New milestone of unified mode
FFMpeg example
After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me
JS multidimensional array to one-dimensional array
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
金仓数据库KingbaseES 插件kdb_database_link
vulnhub HA: Natraj
MC Layer Target
因子选股-打分模型
[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis
How do you use lodash linking function- How do you chain functions using lodash?
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
Leetcode simple question: check whether two string arrays are equal
有道云笔记
FuncS sh file not found when using the benchmarksql tool to test kingbases
商城系统搭建完成后需要设置哪些功能