【BZOJ】3412: [Usaco2009 Dec]Music Notes乐谱(二分)

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

维护前缀和,然后直接二分即可。。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }

const int N=50005;
int a[N], n, m;

int main() {
	read(n); read(m);
	for1(i, 1, n) read(a[i]);
	for1(i, 1, n) a[i]+=a[i-1];
	for1(i, 1, m) {
		printf("%d\n", lower_bound(a+1, a+1+n, getint()+1)-a);
	}
	return 0;
}

 

 


 

Description

 

Input

    第1行:两个整数N,Q.

    第2到N+1行:第i+l行只有一个整数Bi.

    第N+2到N+Q+I行:第N+i+l行只有一个整数Ti.

Output

    第1到Q行:对与每个询问,在词问的时间内,奶牛敲击的是哪个音阶?

Sample Input

3 5
2
1
3
2
3
4
0
1

Sample Output

2
3
3
1
1

HINT

Source

posted @ 2014-09-19 18:34  iwtwiioi  阅读(272)  评论(0编辑  收藏  举报