#include #include #include using i64 = long long; using u64 = unsigned long long; #define REP(i, n) for (int i = 0, REP_N_ = int(n); i < REP_N_; ++i) #define ALL(x) std::begin(x), std::end(x) template inline bool chmax(T &a, T b) { return a < b and ((a = std::move(b)), true); } template inline bool chmin(T &a, T b) { return a > b and ((a = std::move(b)), true); } template using V = std::vector; template std::istream &operator>>(std::istream &is, std::vector &a) { for (auto &x : a) is >> x; return is; } template std::ostream &pprint(const Container &a, std::string_view sep = " ", std::string_view ends = "\n", std::ostream *os = nullptr) { if (os == nullptr) os = &std::cout; auto b = std::begin(a), e = std::end(a); for (auto it = std::begin(a); it != e; ++it) { if (it != b) *os << sep; *os << *it; } return *os << ends; } template struct is_iterable : std::false_type {}; template struct is_iterable())), decltype(std::end(std::declval()))>> : std::true_type {}; template ::value && !std::is_same::value>> std::ostream &operator<<(std::ostream &os, const T &a) { return pprint(a, ", ", "", &(os << "{")) << "}"; } template std::ostream &operator<<(std::ostream &os, const std::pair &a) { return os << "(" << a.first << ", " << a.second << ")"; } #ifdef ENABLE_DEBUG template void pdebug(const T &value) { std::cerr << value; } template void pdebug(const T &value, const Ts &... args) { pdebug(value); std::cerr << ", "; pdebug(args...); } #define DEBUG(...) \ do { \ std::cerr << " \033[33m (L" << __LINE__ << ") "; \ std::cerr << #__VA_ARGS__ << ":\033[0m "; \ pdebug(__VA_ARGS__); \ std::cerr << std::endl; \ } while (0) #else #define pdebug(...) #define DEBUG(...) #endif using namespace std; // Formal Power Series (dense format). template struct DenseFPS { // Coefficients of terms from x^0 to x^DMAX. std::vector coeff_; DenseFPS() : coeff_(1) {} // zero-initialized explicit DenseFPS(std::vector c) : coeff_(std::move(c)) { assert((int)c.size() <= DMAX + 1); } DenseFPS(const DenseFPS &other) : coeff_(other.coeff_) {} DenseFPS(DenseFPS &&other) : coeff_(std::move(other.coeff_)) {} DenseFPS &operator=(const DenseFPS &other) { coeff_ = other.coeff_; return *this; } DenseFPS &operator=(DenseFPS &&other) { coeff_ = std::move(other.coeff_); return *this; } int size() const { return (int)coeff_.size(); } // Returns the coefficient of x^d. T operator[](int d) const { if (d >= size()) return 0; return coeff_[d]; } DenseFPS &operator+=(const T &scalar) { coeff_[0] += scalar; return *this; } friend DenseFPS operator+(const DenseFPS &x, const T &scalar) { DenseFPS res = x; res += scalar; return res; } DenseFPS &operator+=(const DenseFPS &other) { if (size() < other.size()) { coeff_.resize(other.size()); } for (int i = 0; i < other.size(); ++i) coeff_[i] += other[i]; return *this; } friend DenseFPS operator+(const DenseFPS &x, const DenseFPS &y) { DenseFPS res = x; res += y; return res; } DenseFPS &operator-=(const DenseFPS &other) { if (size() < other.size()) { coeff_.resize(other.size()); } for (int i = 0; i < other.size(); ++i) coeff_[i] -= other[i]; return *this; } friend DenseFPS operator-(const DenseFPS &x, const DenseFPS &y) { DenseFPS res = x; res -= y; return res; } DenseFPS &operator*=(const T &scalar) { for (auto &x : coeff_) x *= scalar; return *this; } friend DenseFPS operator*(const DenseFPS &x, const T &scalar) { DenseFPS res = x; res *= scalar; return res; } DenseFPS &operator*=(const DenseFPS &other) { *this = this->mul_naive(other); return *this; } friend DenseFPS operator*(const DenseFPS &x, const DenseFPS &y) { return x.mul_naive(y); } private: // Naive multiplication. O(N^2) DenseFPS mul_naive(const DenseFPS &other) const { const int n = min(size() + other.size() - 1, DMAX + 1); DenseFPS res; res.coeff_.resize(n); for (int i = 0; i < size(); ++i) { for (int j = 0; j < other.size(); ++j) { if (i + j >= n) break; res.coeff_[i + j] += (*this)[i] * other[j]; } } return res; } }; namespace fps { // Fast polynomial multiplication by single NTT. template DenseFPS mul_ntt(const DenseFPS &x, const DenseFPS &y) { static_assert(ModInt::mod() != 1'000'000'007); // Must be a NTT-friendly MOD! auto z = atcoder::convolution(x.coeff_, y.coeff_); if (z.size() > DMAX + 1) { z.resize(DMAX + 1); } return DenseFPS(std::move(z)); } } // namespace fps using mint = atcoder::modint998244353; const int MOD = 998244353; const int PMAX = 6'000; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; V A(N); cin >> A; sort(ALL(A)); V> ps(N + 1); V prods(N + 1); prods[0] = 1; REP(i, N) prods[i + 1] = prods[i] * A[i]; DenseFPS f; f += 1; ps[N] = f; REP(i, N) { int ri = N - 1 - i; DenseFPS g(std::vector(2)); g.coeff_[0] = A[ri] - 1; g.coeff_[1] = 1; ps[ri] = fps::mul_ntt(ps[ri + 1], g); } REP(i, Q) { int l, r, p; cin >> l >> r >> p; u64 ans = 0; for (int x = l; x <= r; ++x) { int j = lower_bound(A.begin(), A.end(), x) - A.begin(); mint count = ps[j][p] * prods[j]; ans ^= count.val(); } ans %= MOD; cout << ans << '\n'; } }