#include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; const ll MOD = 998244353; template class ModInt { ll a; public: constexpr ModInt(const ll a = 0) noexcept : a((a % mod + mod) % mod) {} constexpr ll &value() noexcept { return a; } constexpr ModInt operator + (const ModInt &rhs) const noexcept { return ModInt(*this) += rhs; } constexpr ModInt operator - (const ModInt &rhs) const noexcept { return ModInt(*this) -= rhs; } constexpr ModInt operator * (const ModInt &rhs) const noexcept { return ModInt(*this) *= rhs; } constexpr ModInt operator / (const ModInt &rhs) const noexcept { return ModInt(*this) /= rhs; } constexpr ModInt &operator += (const ModInt &rhs) noexcept { a += rhs.a; if (a >= mod) a -= mod; return *this; } constexpr ModInt &operator -= (const ModInt &rhs) noexcept { a += mod - rhs.a; if (a >= mod) a -= mod; return *this; } constexpr ModInt &operator *= (const ModInt &rhs) noexcept { a = a * rhs.a % mod; return *this; } constexpr ModInt pow(ll t) const noexcept { if (t == 0) return 1; auto ret = pow(t >> 1); ret *= ret; if (t & 1) ret *= *this; return ret; } constexpr ModInt inv() const noexcept { return pow(mod - 2); } constexpr ModInt operator /=(const ModInt &rhs) { return (*this) *= rhs.inv(); } constexpr bool operator == (const ModInt &rhs) const noexcept { return this->a == rhs.a; } constexpr bool operator != (const ModInt &rhs) const noexcept { return this->a != rhs.a; } friend constexpr ostream &operator << (ostream &os, const ModInt &rhs) noexcept { return os << rhs.a; } friend constexpr istream &operator >> (istream &is, ModInt &rhs) { is >> rhs.a; return is; } }; using mint = ModInt; typedef pair P; int main() { int n, q; cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); vector as(n + 1, 1); for (int i = 0; i < n; i++) as[i + 1] = as[i] * a[i]; map mp; vector l(q), r(q), p(q); for (int i = 0; i < q; i++) { cin >> l[i] >> r[i] >> p[i]; for (int j = l[i]; j <= r[i]; j++) { int idx = lower_bound(a.begin(), a.end(), j) - a.begin(); mp[{n - idx, p[i]}] = true; } } reverse(a.begin(), a.end()); map val; vector> dp(2, vector(n + 1, 0)); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j <= n; j++) { dp[1][j] = dp[0][j] * (a[i] - 1); if (j) dp[1][j] += dp[0][j - 1]; if (mp[{i + 1, j}]) val[{i + 1, j}] = dp[1][j]; } swap(dp[0], dp[1]); } reverse(a.begin(), a.end()); for (int i = 0; i < q; i++) { ll ret = 0; for (int j = l[i]; j <= r[i]; j++) { int idx = lower_bound(a.begin(), a.end(), j) - a.begin(); mint x = as[idx] * val[{n - idx, p[i]}]; ret ^= x.value(); } cout << ret % MOD << endl; } return 0; }