#include <bits/stdc++.h>
using namespace std;
#define debug(a) cerr << #a << " = " << (a) << nl;
#define ll long long
#define nl '\n'
const int mod = 1e9+7;
const int N = 1e5+3;
int bigmod(int a, int b)
{
int ans = 1;
while (b > 0)
{
if (b & 1)
ans = (ans * 1ll * a) % mod;
a = (a * 1ll * a) % mod;
b >>= 1;
}
return ans;
}
inline int add(int x, int y)
{
return (x + y >= mod ? x + y - mod : x + y);
}
inline int sub(int x, int y)
{
return (x - y < 0 ? x - y + mod : x - y);
}
inline int gun(int x, int y)
{
return ((x * 1ll * y) % mod);
}
inline int vag(int x, int y)
{
return (x * 1ll * bigmod(y, mod - 2)) % mod;
}
void TestCases()
{
ll n,q;
cin>>n>>q;
ll a[n];
ll odd[n+1];
for(int i=0;i< n ;i++){
cin>>a[i];
}
odd[0]=0;
odd[1]=a[0]%2;
for(int j=1;j<n ;j++){
odd[j+1]=add(odd[j],(a[j]%2));
}
while(q-- ){
ll op,l,r;
cin>>op>>l>>r;
if(op==0){
ll ache=odd[r]-odd[l-1];
ll even=(r-l+1)-ache;
ll first=sub(bigmod(2,even),1);
ll sec=sub(bigmod(2,ache-1),1);
if(ache==0)sec=0;
if(even==0)first=0;
ll total=add(first,sec);
total=add(total,gun(first,sec));
cout<<total<<nl;
}
else{
ll ache=odd[r]-odd[l-1];
ll even=(r-l+1)-ache;
ll first=sub(bigmod(2,ache-1),0);
ll sec=sub(bigmod(2,even),1);
ll total=add(first,gun(first,sec));
if(ache==0)total=0;
cout<<total<<nl;
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1, cs = 0;
//cin >> t;
while (t--){
// cout << "Case " << ++cs << ": ";
TestCases();
}
return 0;
}