BZOJ——3412: [Usaco2009 Dec]Music Notes曲譜

http://www.lydsy.com/JudgeOnline/problem.php?id=3412

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 206  Solved: 162
[Submit][Status][Discuss]

Description

 

 

Input

    第1行:兩個整數N,Q.php

    第2到N+1行:第i+l行只有一個整數Bi.spa

    第N+2到N+Q+I行:第N+i+l行只有一個整數Ti.code

 

Output

    第1到Q行:對與每一個詢問,在詞問的時間內,奶牛敲擊的是哪一個音階?blog

Sample Input

3 5
2
1
3
2
3
4
0
1

Sample Output

2
3
3
1
1

HINT

 

Source

Silverip

 

 1 #include <algorithm>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 inline void read(int &x)
 7 {
 8     x=0; register char ch=getchar();
 9     for(; ch>'9'||ch<'0'; ) ch=getchar();
10     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
11 }
12 
13 const int N(5e4+5);
14 int n,q,sum[N];
15 
16 int Presist()
17 {
18     read(n),read(q);
19     for(int i=1; i<=n; ++i)
20         read(sum[i]),sum[i]+=sum[i-1];
21     for(int x; q--; )
22     {
23         read(x);
24         printf("%d\n",upper_bound(sum+1,sum+n+1,x)-sum);
25     }
26     return 0;
27 }
28 
29 int Aptal=Presist();
30 int main(int argc,char**argv){;}
相關文章
相關標籤/搜索