#include <vector>
#include <functional>

template<class T, class E, class F, class G, class H>
struct lazy_segment_tree {
	using value_type = T;
	using operand_type = E;
	using size_type = std::size_t;
private :
	class node_type {
	public :
		value_type value;
		operand_type operand;
		node_type () = default;
		node_type (const value_type &value, const operand_type &operand)
		noexcept : value(value), operand(operand) { }
	};

	const F f;
	const G g;
	const H h;
	const value_type value_identity;
	const operand_type operand_identity;
	std::vector<node_type> node;

	value_type reflect (const size_type &i) const noexcept {
		if (node[i].operand == operand_identity) return node[i].value;
		return g(node[i].value, node[i].operand);
	}

	void merge (const size_type &i) noexcept {
		node[i].value = f(reflect(i << 1 | 0), reflect(i << 1 | 1));
	}

	void add (const size_type &i, const operand_type &operand) noexcept {
		node[i].operand = h(node[i].operand, operand);
	}

	void propagate (size_type i) noexcept {
		if (node[i].operand == operand_identity) return;
		add(i << 1 | 0, node[i].operand);
		add(i << 1 | 1, node[i].operand);
		node[i].value = reflect(i);
		node[i].operand = operand_identity;
	}

	void topdown_update (size_type i) noexcept {
		if (i == 0) return;
		for (size_type h = 32 - __builtin_clz(i); h; h--) {
			propagate(i >> h);
		}
	}

	void bottomup_update (size_type i) noexcept {
		for (i >>= 1; i > 0; i >>= 1) merge(i);
	}

public :
	lazy_segment_tree (const value_type &value_identity, const operand_type &operand_identity, const F &f, const G &g, const H &h)
	noexcept : value_identity(value_identity), operand_identity(operand_identity), f(f), g(g), h(h) { }

	lazy_segment_tree (size_type n, const value_type &value_identity, const operand_type &operand_identity, const F &f, const G &g, const H &h)
	noexcept : node(n << 1, node_type(value_identity, operand_identity)), value_identity(value_identity), operand_identity(operand_identity), f(f), g(g), h(h) { }

	lazy_segment_tree (size_type n, const value_type &value, const value_type &value_identity, const operand_type &operand_identity, const F &f, const G &g, const H &h)
	noexcept : node(n << 1, node_type(value_identity, operand_identity)), value_identity(value_identity), operand_identity(operand_identity), f(f), g(g), h(h) {
		for (size_type i = size(); i < node.size(); i++) node[i].value = value;
		for (size_type i = size(); i --> 0;) merge(i);
	}

	template<class InputIterator>
	lazy_segment_tree (InputIterator first, InputIterator last, const value_type &value_identity, const operand_type &operand_identity, const F &f, const G &g, const H &h)
	noexcept : node(((last - first) << 1), node_type(value_identity, operand_identity)), value_identity(value_identity), operand_identity(operand_identity), f(f), g(g), h(h) {
		for (size_type i = size(); first != last; first++, i++) node[i].value = (*first);
		for (size_type i = size(); i --> 0;) merge(i);
	}

	size_type size () const noexcept {
		return (node.size() >> 1);
	}

	void assign (size_type _size) noexcept {
		node.assign(_size << 1, node_type(value_identity, operand_identity));
	}

	void assign(size_type _size, const value_type &value) noexcept {
		assign(_size);
		for (size_type i = size(); i < node.size(); i++) node[i].value = value;
		for (size_type i = size(); i --> 0;) merge(i);
	}

	template<class InputIterator>
	void assign (InputIterator first, InputIterator last) noexcept {
		assign(last - first);
		for (size_type i = size(); first != last; first++, i++) node[i].value = (*first);
		for (size_type i = size(); i --> 0;) merge(i);
	}

	void update (size_type first, size_type last, const operand_type &operand) noexcept {
		const size_type _first = first + size(), _last = last + size() - 1;
		topdown_update(_first);
		topdown_update(_last);
		for (first += size(), last += size(); first != last; first >>= 1, last >>= 1) {
			if (first & 1) add(first++, operand);
			if (last  & 1) add(--last,  operand);
		}
		bottomup_update(_first);
		bottomup_update(_last);
	}

	value_type fold (size_type first, size_type last) noexcept {
		topdown_update(first + size());
		topdown_update(last + size() - 1);
		value_type left = value_identity, right = value_identity;
		for (first += size(), last += size(); first != last; first >>= 1, last >>= 1) {
			if (first & 1) left = f(left, reflect(first++));
			if (last & 1) right = f(reflect(--last), right);
		}
		return f(left, right);
	}

};

template<class InputIterator, class T, class E, class F, class G, class H>
lazy_segment_tree<T, E, F, G, H> make_lazysegtree (InputIterator first, InputIterator last, const T &value_identity, const E &operand_identity, const F &f, const G &g, const H &h) {
	return lazy_segment_tree<T, E, F, G, H>(first, last, value_identity, operand_identity, f, g, h);
}

#include <iostream>
#include <cstdint>
#include <cassert>

template<std::int_fast32_t Modulus>
struct modint {
	using value_type = std::int_fast32_t;

	static constexpr std::int_fast32_t mod = Modulus;
	static_assert(mod > 1, "Modulus must be greater than 1");

private :
	value_type x;

	template<class T>
	static constexpr value_type normalize (T value) noexcept {
		if (value < 0) {
			value = (-value) % mod;
			return (value ? value : mod - value);
		}
		return (value % mod);
	}

public :
	constexpr modint () noexcept : x(0) { }

	template<class T>
	constexpr modint (T value) noexcept : x(normalize(value)) { }

	constexpr modint operator+ () const noexcept {
		return modint(*this);
	}

	constexpr modint operator- () noexcept {
		if (x != 0) x = mod - x;
		return modint(*this);
	}

	constexpr modint &operator+= (const modint &p) noexcept {
		if ((x += p.x) >= mod) x -= mod;
		return (*this);
	}

	constexpr modint &operator-= (const modint &p) noexcept {
		if ((x += mod - p.x) >= mod) x -= mod;
		return (*this);
	}

	constexpr modint &operator*= (const modint &p) noexcept {
		x = (int)(1LL * x * p.x % mod);
		return (*this);
	}

	constexpr modint &operator/= (const modint &p) noexcept {
		return ((*this) *= p.inverse());
	}

	constexpr modint operator+ (const modint &p) const noexcept {
		return (modint(*this) += p);
	}

	constexpr modint operator- (const modint &p) const noexcept {
		return (modint(*this) -= p);
	}

	constexpr modint operator* (const modint &p) const noexcept {
		return (modint(*this) *= p);
	}

	constexpr modint operator/ (const modint &p) const noexcept {
		return (modint(*this) /= p);
	}

	constexpr bool operator== (const modint &p) const noexcept {
		return (x == p.x);
	}

	constexpr bool operator!= (const modint &p) const noexcept {
		return (x != p.x);
	}

	constexpr modint pow (long long exp) const noexcept {
		modint value(1), buff(x);
		while (exp) {
			if (exp & 1) value *= buff;
			buff *= buff;
			exp >>= 1;
		}
		return value;
	}

	constexpr modint inverse () const noexcept {
		return pow(Modulus - 2);
	}

	friend std::ostream &operator<< (std::ostream &os, const modint &p) {
		return (os << p.x);
	}

	friend std::istream &operator>> (std::istream &is, modint &p) {
		long long v;
		is >> v;
		p = modint(v);
		return (is);
	}

};

#include <bits/stdc++.h>

constexpr int MOD = 998'244'353;

using sum = std::pair<modint<MOD>, int>;
using affine = std::pair<modint<MOD>, modint<MOD>>;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	int n, q;
	std::cin >> n >> q;
	std::vector<sum> node;
	for (int i = 0; i < n; i++) {
		modint<MOD> value;
		std::cin >> value;
		node.emplace_back(value, 1);
	}
	
	auto f = [](const sum &a, const sum &b) {
		return sum(a.first + b.first, a.second + b.second);
	};
	auto g = [](const sum &a, const affine &b) {
		return sum(a.first * b.first + b.second * a.second, a.second);
	};
	auto h = [](const affine &a, const affine &b) {
		return affine(a.first * b.first, a.second * b.first + b.second);
	};
	
	auto seg = make_lazysegtree(node.begin(), node.end(), sum(0, 0), affine(1, 0), f, g, h);
	
	while (q--) {
		int type;
		std::size_t l, r;
		std::cin >> type >> l >> r;
		if (type == 0) {
			modint<MOD> b, c;
			std::cin >> b >> c;
			seg.update(l, r, affine(b, c));
		} else {
			std::cout << seg.fold(l, r).first << '\n';
		}
	}
	
	return 0;
}


Measured memory_bytes: 42404