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

【BZOJ】3412: [Usaco2009 Dec]Music Notes乐谱(二分)的更多相关文章

  1. BZOJ——3412: [Usaco2009 Dec]Music Notes乐谱

    http://www.lydsy.com/JudgeOnline/problem.php?id=3412 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit:  ...

  2. BZOJ 3412: [Usaco2009 Dec]Music Notes乐谱(离线处理)

    这道题貌似怎么写都可以吧= =,我先读入询问然后从小到大处理就行了= = PS:水水题真的好!无!聊!但是好!欢!乐! CODE: #include<cstdio>#include< ...

  3. BZOJ3412: [Usaco2009 Dec]Music Notes乐谱

    3412: [Usaco2009 Dec]Music Notes乐谱 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 35  Solved: 30[Sub ...

  4. BZOJ 3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者(贪心)

    这= =,就是线段覆盖对了= =直接贪心就行了= = CODE: #include<cstdio>#include<iostream>#include<cstring&g ...

  5. [bzoj 1774][Usaco2009 Dec]Toll 过路费

    题目描述 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫约翰上交过路费 ...

  6. bzoj 1774: [Usaco2009 Dec]Toll 过路费 ——(改)floyd

    Description 跟所有人一样,农夫约翰以着宁教我负天下牛,休叫天下牛负我的伟大精神,日日夜夜苦思生 财之道.为了发财,他设置了一系列的规章制度,使得任何一只奶牛在农场中的道路行走,都 要向农夫 ...

  7. BZOJ 3410 [Usaco2009 Dec]Selfish Grazing 自私的食草者:贪心【最多线段覆盖】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1324 题意: 给你n个区间,问你最多能选择多少个区间使得它们不相互覆盖. 题解: RQ ...

  8. bzoj 1774: [Usaco2009 Dec]Toll 过路费【排序+Floyd】

    非常迷的一道题啊 我觉得挺对的版本只得了30 总之就是Floyd·改,开两个数组,一个是d[i][j]就是普通的只有边权的最短路,a[i][j]是题目要求的那种 具体改的地方是把枚举中转点的地方把中转 ...

  9. BZOJ 2097: [Usaco2010 Dec]Exercise 奶牛健美操 二分 + 贪心 + 树上问题

    Code: #include<bits/stdc++.h> using namespace std; #define setIO(s) freopen(s".in",& ...

随机推荐

  1. 一个简单的int型C++单链表的实现

    IntSLList.h //************************ intSLList.h ************************** // singly-linked list ...

  2. MySql sqlstate代码大全(转载)

    http://blog.csdn.net/u013847120/article/details/52887813 本章列出了当你用任何主机语言调用MySQL时可能出现的错误.首先列出了服务器错误消息. ...

  3. python中,== 与 is 之间区别

    在python中,== 与 is 之间既有区别,又有联系,本文将通过实际代码的演示,力争能够帮助读到这篇文章的朋友以最短的时间理清二者的关系,并深刻理解它们在内存中的实现机制. 扯淡的话不多说,下面马 ...

  4. 我装win8与win7双系统的血泪史

    前段时间教徒弟装系统,由于笔记本原带了win8,他不想换掉原来的系统.遂决定装个双系统.于是按照之前的一贯套路,但是出现了问题. 一. 首先遇到的问题是:如何进入BIOS,设置成U盘启动.Win XP ...

  5. Can rename table but can not truncate table

    一个表无法truncate可是能够rename,这个乍听起来认为好奇怪,以下模拟该过程. 3个session: session1运行truncate和rename操作. session2运行lock表 ...

  6. mongodb - mongotop

    mongodb - mongotop # ./mongotop 2016-03-12T16:37:32.141+0800 connected to: 127.0.0.1 ns total read w ...

  7. MVC :“已添加了具有相同键的项”

    最近将一个项目从ASP.NET MVC 3升级至刚刚发布的ASP.NET MVC 5.1,升级后发现一个ajax请求出现了500错误,日志中记录的详细异常信息如下: System.ArgumentEx ...

  8. Hadoop文件解压缩

    Class org.apache.hadoop.io.compress .CompressionCodecFactory A factory that will find the correct co ...

  9. Atom打开报错:"Cannot load the system dictionary for zh-CN"

    1. 问题描述 最近每次使用atom打开文件,总是报错"Cannot load the system dictionary for zh-CN" 2. 解决方法 File --&g ...

  10. 基于maven的ssh框架一步一步搭建(一)

    一.新建maven项目,配置ssh框架pom的最低支持 1.新建一个maven项目 2.添加一个web.xml ? 1 2 3 4 5 6 7 8 9 <?xml version="1 ...