#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template struct modint{ u32 val; modint(): val(0){} template modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;} modint pow(ll k) const { modint res(1), x(val); while(k){ if(k&1) res *= x; x *= x; k >>= 1; } return res; } template modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;} modint inv() const {return pow(M-2);} modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;} modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;} modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;} modint& operator/=(modint a){return (*this) *= a.inv();} modint operator+(modint a) const {return modint(val) +=a;} modint operator-(modint a) const {return modint(val) -=a;} modint operator*(modint a) const {return modint(val) *=a;} modint operator/(modint a) const {return modint(val) /=a;} modint operator-(){return modint(M-val);} bool operator==(const modint a) const {return val == a.val;} bool operator!=(const modint a) const {return val != a.val;} bool operator<(const modint a) const {return val < a.val;} }; using mint = modint; int main() { int n, q; cin >> n >> q; vector dp(n+1); // reversed!!! dp[0] = 1; int cnt = 0; vector v(n); for (int i = 0; i < n; ++i) { scanf("%d", &v[i]); for (int j = n-1; j >= 0; --j) { dp[j+1] += dp[j]*mint(v[i]-1); } cnt++; } sort(v.begin(),v.end()); vector> event; vector ps(q); for (int i = 0; i < q; ++i) { int l, r; scanf("%d %d %d", &l, &r, &ps[i]); for (int j = l; j <= r; ++j) { event.emplace_back(j, i); } } set s; sort(event.begin(),event.end()); int cur = 0; vector ans(q); for (int i = 0; i < event.size(); ++i) { while(cur < v.size() && event[i].first > v[cur]){ for (int j = 0; j < n; ++j) { dp[j+1] -= dp[j]*(v[cur]-1); } for (int j = 0; j <= n; ++j) { dp[j] *= mint(v[cur]); } cnt--; cur++; } if(cnt >= ps[event[i].second]) ans[event[i].second] ^= dp[cnt-ps[event[i].second]].val; } for (int i = 0; i < q; ++i) { printf("%d\n", ans[i]); } return 0; }