forked from Sahaj-Bamba/HacktoberTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha4.cpp
More file actions
35 lines (35 loc) · 635 Bytes
/
a4.cpp
File metadata and controls
35 lines (35 loc) · 635 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<bits/stdc++.h>
#include<math.h>
#define rep(k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 1000000007
using namespace std;
ll ar[1000005];
int main()
{
int n,q,x,y;
int ar[100005];
char str[100005];
scanf("%d %d",&n,&q);
getchar();
ar[0]=0;
rep(1,n+1)
{
str[i]=getchar();
if(str[i]=='1')
ar[i]=1;
else
ar[i]=0;
ar[i]+=ar[i-1];
}
long long ans,po[100005];
po[0]=1;
for(int i=1;i<=n;i++)
po[i]=(2*po[i-1])%MOD;
for(int i=0;i<q;i++)
{
scanf("%d %d",&x,&y);
ans=(((po[ar[y]-ar[x-1]]-1)*(po[y-x+1-(ar[y]-ar[x-1])])))%MOD;
printf("%lld\n",ans);
}
}