链接:https://codeforces.com/group/nhsfFrN6WT/contest/266629/problem/C

JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.

First, he splits the Banh-mi into nn parts, places them on a row and numbers them from 11 through nn. For each part ii, he defines the deliciousness of the part as xi∈{0,1}xi∈{0,1}. JATC's going to eat those parts one by one. At each step, he chooses arbitrary remaining part and eats it. Suppose that part is the ii-th part then his enjoyment of the Banh-mi will increase by xixi and the deliciousness of all the remaining parts will also increase by xixi. The initial enjoyment of JATC is equal to 00.

For example, suppose the deliciousness of 33 parts are [0,1,0][0,1,0]. If JATC eats the second part then his enjoyment will become 11 and the deliciousness of remaining parts will become [1,_,1][1,_,1]. Next, if he eats the first part then his enjoyment will become 22 and the remaining parts will become [_,_,2][_,_,2]. After eating the last part, JATC's enjoyment will become 44.

However, JATC doesn't want to eat all the parts but to save some for later. He gives you qq queries, each of them consisting of two integers lili and riri. For each query, you have to let him know what is the maximum enjoyment he can get if he eats all the parts with indices in the range [li,ri][li,ri] in some order.

All the queries are independent of each other. Since the answer to the query could be very large, print it modulo 109+7109+7.

Input

The first line contains two integers nn and qq (1≤n,q≤1000001≤n,q≤100000).

The second line contains a string of nn characters, each character is either '0' or '1'. The ii-th character defines the deliciousness of the ii-th part.

Each of the following qq lines contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n) — the segment of the corresponding query.

Output

Print qq lines, where ii-th of them contains a single integer — the answer to the ii-th query modulo 109+7109+7.

Examples

input

Copy

4 2
1011
1 4
3 4

output

Copy

14
3

input

Copy

3 2
111
1 2
3 3

output

Copy

3
1

Note

In the first example:

  • For query 11: One of the best ways for JATC to eats those parts is in this order: 11, 44, 33, 22.
  • For query 22: Both 33, 44 and 44, 33 ordering give the same answer.

In the second example, any order of eating parts leads to the same answer.

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,t,k,c,sum,mod=1e9+7,vis=1,q,mx=0,kk=0,y=0;
long long l,r,s[10000001];
char x[1000001];
long long pow_m(long long a, long long b)
{long long ans = 1;while(b > 0){if(b & 1){ans = ans * a % mod;}a = a * a % mod;b >>= 1; } return ans;
}
int main()
{scanf("%lld %lld\n",&n,&q);cin>>x;sum=0;for(int i=0;i<n;i++){if(x[i]=='1')sum++;s[i+1]=sum;}for(int i=1;i<=q;i++){cin>>l>>r;c=s[r]-s[l-1];k=r-l+1;if(c==0)cout<<0<<endl;else{long long ss=pow_m(2,c)-1;long long kk=pow_m(2,k-c);long long ans=kk*ss;ans%=mod;cout<<ans<<endl;}}}

C. Banh-mi相关推荐

  1. 您的用户界面是您产品不会因心灵感应而谦卑的补偿

    by Morten Just 由Morten Just 您的用户界面是您产品不会因心灵感应而谦卑的补偿 (Your UI is your product's humble compensation f ...

  2. BootStrap入门教程 (四)

    上讲回顾:Bootstrap组件丰富同时具有良好可扩展性,能够很好地应用在生产环境.这些组件包括按钮(Button),导航(Navigation),缩略图( thumbnails),提醒(Alert) ...

  3. 4.18、Bootstrap V4自学之路-----内容---滚动监听

    为什么80%的码农都做不了架构师?>>>    总体来说,用起来不是特别满意,先放一放吧. 导航条示例 滚动监听插件会根据滚动的位置,自动更新导航条的目标.滚动在导航条下面的区域,查 ...

  4. ng-bootstrap 组件集中 tabset 组件的实现分析

    ng-bootstrap: tabset 本文介绍了 ng-bootstrap 项目中,tabset 的实现分析. 使用方式 <ngb-tabset> 作为容器元素,其中的每个页签以一个 ...

  5. 一起领略css3动画的强大

    CSS3的确出了不少高大上的功能,3D效果/动画/多列等等;今天写篇文章记录怎么一下怎么用CSS3写一个动画;不过还是要提醒大家:IE9及以下版本不支持CSS3动画(需要可以考虑用js,不过估计效果不 ...

  6. Bootstrap学习js插件篇之提示框

    案例 受到Jason Frame开发的jQuery.tipsy插件的启发,我们才把这个工具提示插件做的更好,而且此插件不依赖图片,只是使用CSS3来实现动画效果,并使用data属性存储标题. 将鼠标悬 ...

  7. 前端基础之《Bootstrap(13)—JavaScript插件_标签页、工具提示、弹出框、折叠效果和幻灯片》

    一.data-开头的是什么 是bootstrap封装的js. data-toggle data-target data-dismiss data-spy 参考资料:https://blog.csdn. ...

  8. JavaScript 插件

    概览 单个还是全部引入 JavaScript 插件可以单个引入(使用 Bootstrap 提供的单个 *.js 文件),或者一次性全部引入(使用 bootstrap.js 或压缩版的 bootstra ...

  9. a按钮居中显示 bootstrap_Bootstrap提示冒泡样式

    使用提示冒泡持件时的注意事项: Tooltip提示冒泡组件依赖于 Popper.js ,你必须将popper.min.js 文件放在 bootstrap.js之前调用,或者使用 bootstrap.b ...

  10. 4.5Bootstrap学习js插件篇之工具提示

    案例 受到Jason Frame开发的jQuery.tipsy插件的启发,我们才把这个工具提示插件做的更好,而且此插件不依赖图片,只是使用CSS3来实现动画效果,并使用data属性存储标题. 将鼠标悬 ...

最新文章

  1. Oracle 11g sys,system 密码忘记设置解决办法
  2. decisiontreeregressor_机器学习算法-Decision Tree
  3. GDCM:gdcm::TagPath的测试程序
  4. 每天一道LeetCode-----给定二维数组代表海域和岛屿,计算有多少个孤岛
  5. 网易2019实习生招聘题目 被3整除
  6. python拟牛顿法迭代点绘制_最速下降法、牛顿法、拟牛顿法,Python实现高维二次目标函数优化...
  7. sqlserver迁移到mysql遇到的那些坑
  8. 一阶电路暂态响应的结果分析。_阻尼比测试方法及谐响应分析
  9. MySQL数据库技术与应用:数据查询
  10. iOS开发中经常用的实用代码合集
  11. 记事本编写java_编写运行最简单的java程序——使用记事本编写java程序
  12. visual foxpro c语言教程,VFP简单初级入门教程超好.pdf
  13. 合成PDF文档,合并PDF文档
  14. Everything使用攻略和技巧
  15. SSM基于小程序的医院预约挂号系统 毕业设计-附源码260839
  16. C语言图书用国际标准书号,图书登记管理系统程序ds.doc
  17. 第九章 亚瑟龙的召唤
  18. spring boot通用办事流程管理软件 毕业设计-附源码211819
  19. 小米手机第三方卡刷软件_小米手机通用详细图形刷机教程(四): 刷入第三方系统...
  20. java的套娃汇总(黑马程序员基础java总结)

热门文章

  1. html实现圆形图片
  2. html语言亚马逊后台,「亚马逊」新手卖家指南-页面与术语
  3. 2015人生感悟哲理
  4. Elasticsearch 集群报错 master not discovered yet
  5. 人脸识别打卡机怎么调sj_人脸通怎么使用_人脸通考勤机怎么设置
  6. 股票大作手杰西·利弗莫尔语录集锦
  7. 大数据时代下的网络安全与数据隐私论文
  8. 基于STM32的DDS信号发生器
  9. 为了对电脑进行保护,已经阻止此应用
  10. 远程访问及控制工具SSH