#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic warning "-std=c++11"
using ll = long long;
const ll mod = 1e9 + 7;
#define sqr( a ) ( ( a ) * ( a ) )
const int sz = 1e5 + 10;
int n, q;
int t, l, r;
int ar[sz];
ll pw[sz];
ll ans;
ll solve( int l, int r ) {
ll ret = 0;
int od = ar[r] - ar[l - 1];
int ev = r - l + 1 - od;
ret = ( pw[ev] - 1ll + mod ) % mod;
ll od_sum_sv = od >= 1 ? ( pw[od - 1] - 1ll + mod ) % mod : 0ll;
ll hand = ( od_sum_sv * pw[ev] ) % mod;
ret = ( ret + hand ) % mod;
return ret;
}
int main() {
pw[0] = 1ll;
for( int i=1; i<sz; i++ ) pw[i] = ( pw[i - 1] * 2ll ) % mod;
cin >> n >> q;
assert( 1 <= n && n <= 100000 );
assert( 1 <= q && q <= 100000 );
for( int i=1; i<=n; i++ ) {
cin >> ar[i];
assert( 1 <= ar[i] && ar[i] <= 1000000000 );
ar[i] %= 2;
ar[i] += ar[i - 1];
}
while( q-- ) {
cin >> t >> l >> r;
assert( 0 <= t && t <= 1 );
assert( 1 <= l && l <= n );
assert( 1 <= r && r <= n );
if( t == 1 ) {
ans = ( pw[r - l + 1] - 1ll + mod ) % mod;
ans = ( ans - solve( l, r ) + mod ) % mod;
}
else {
ans = solve( l, r );
}
cout << ans << "\n";
}
return 0;
}