水题,记录一下low_bound(*begin,*end,num),其中low-bound是指以num为下界,寻找第一个比num大或相等的元素的指针,通过减去*begin指针我们可以获得相应的下标。

upper_bound( first, last, & val)算法返回一个非递减序列[first, last)中第一个 大于 val的地址。 
lower_bound( first, last, & val)算法返回一个非递减序列[first, last)中第一个 大于等于 值val的地址。

区别好像就是lower_bound会返回等于的值,但是upper_bound是严格大于。

AC代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
ll n,m,a[maxn],b[maxn],sum[maxn];
int main(){ios::sync_with_stdio(false);cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];sum[i]=sum[i-1]+a[i];}for(int i=1;i<=m;i++)cin>>b[i];for(int i=1;i<=m;i++){//ll index=upper_bound(sum,sum+n+1,b[i])-sum;ll index=lower_bound(sum,sum+n+1,b[i])-sum;cout<<index<<" "<<b[i]-sum[index-1]<<endl;}
}

Letters CodeForces - 978C(水题,low_bound()函数使用)相关推荐

  1. codeforces 1041a(水题)

    http://codeforces.com/problemset/problem/1041/A(题目链接) There was an electronic store heist last night ...

  2. 闲来无事刷水题、简单博弈论专题、sg函数、洛谷

    记 今天闲来无事,不想刷codeforces了,到洛谷提高组训练营找几道水题刷着玩玩(虽然自己早已过了打OI的年纪)- 简单博弈论专题 P1199 三国游戏 这么考虑,由于电脑总是不能让我搭配出当前能 ...

  3. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

  4. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

  5. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  6. 【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

    题干: Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wa ...

  7. 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)

    题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...

  8. Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  9. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

最新文章

  1. JVM调优:基本垃圾回收算法
  2. crontab工具介绍
  3. 【C 语言】二级指针作为输入 ( 二维数组 | 二维数组内存大小计算 | 指针跳转步长问题 )
  4. LIVE555再学习 -- testRTSPClient 源码分析
  5. IntelliJ IDEA for Mac 修改项目模块的名称
  6. 还是想继续写代码,不想这么快就去养猪~
  7. 计算领域的致敬与前行
  8. discuz mysql 类_discuz7 phpMysql操作类
  9. 【TensorFlow】TensorFlow从浅入深系列之八 -- 教你学会变量管理
  10. S2D_基于深度学习的视觉稠密建图和定位_相关文章
  11. Julia: [1 +j] ==[1 + j] ?
  12. 圆面积公式积分法推导
  13. 【nodejs】mocha+chai+nyc基础
  14. 【SpringBoot】之自定义 Filter 过滤器
  15. 路由器交换与配置综合实验(二)外网
  16. Linux驱动——mmc sd card 块设备读写流程(十三)
  17. 网狐棋牌为服务器大厅加载游戏注意事项
  18. 【FPGA教程案例96】控制案例1——基于FPGA的自适应PID控制器verilog实现
  19. 张国宝:东北地区经济社会发展加快
  20. 这份“插件英雄榜Top40”才是Chrome的正确打开方式!(Github7000+ Stars)

热门文章

  1. this和spuer的区别
  2. SRC部落,国家、企业和安全人才的三方求和
  3. 微信公众号调用地图:导航
  4. 你好世界,我来自遥远的东方,请问你是哪里的高人?
  5. PowerManager之WakeLock源码解析
  6. 生物神经网络与机器学习的碰撞,Nature论文提出DNA试管网络识别手写数字
  7. 我的第一次实质性开源贡献——Apache IoTDB
  8. 两个YATE服务器互联的实现
  9. 2013读书摘抄(二)
  10. 计算机毕业设计ssm基于WEB的儿童运动馆业务信息系统