This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "../../../../template/template.hpp"
#define PROBLEM "https://judge.yosupo.jp/problem/range_affine_point_get"
#include "../../../../data-structure/segment-tree/DualSegmentTree.hpp"
#define MOD 998244353
using S = lint;
struct F {
lint a;
lint b;
};
S mapping(F f, S x) {
return ((x * f.a) % MOD + f.b) % MOD;
}
F composition(F f, F g) {
return {(f.a * g.a) % MOD, ((f.a * g.b) % MOD + f.b) % MOD};
}
F id() {
return {1, 0};
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
in(n, q);
vector<S> a(n);
in(a);
DualSegmentTree<S, F, mapping, composition, id> seg(a);
rep(i, q) {
int com;
in(com);
if (com == 0) {
int l, r;
lint b, c;
in(l, r, b, c);
seg.apply(l, r, {b, c});
} else {
int p;
in(p);
out(seg.get(p));
}
}
}
#line 2 "template/template.hpp"
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
ostream &operator<<(ostream &dest, __int128_t value) {
ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(ios_base::badbit);
}
}
return dest;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != (int)v.size() ? " " : "");
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if (itr != set_var.end()) os << " ";
itr--;
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set_var) {
for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if (itr != set_var.end()) os << " ";
itr--;
}
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
os << itr->first << " -> " << itr->second << "\n";
}
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const unordered_map<T, U> &map_var) {
for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
os << itr->first << " -> " << itr->second << "\n";
}
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
os << pair_var.first << " " << pair_var.second;
return os;
}
void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
cout << a;
(cout << ... << (cout << ' ', b));
cout << '\n';
}
void outf() { cout << '\n'; }
template <class T, class... Ts>
void outf(const T &a, const Ts &...b) {
cout << fixed << setprecision(14) << a;
(cout << ... << (cout << ' ', b));
cout << '\n';
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v) is >> in;
return is;
}
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
template <typename T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};
#pragma endregion
#line 2 "verify/LibraryChecker/data-structure/segment-tree/RangeAffinePointGet.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/range_affine_point_get"
#line 2 "data-structure/segment-tree/DualSegmentTree.hpp"
template <class S, class F, auto mapping, auto composition, auto id>
struct DualSegmentTree {
private:
int n;
vector<F> node;
vector<S> ar;
F ID;
void Apply(int a, int b, F x, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
eval(k, l, r);
if (r <= a || b <= l) return;
if (a <= l && r <= b) {
node[k] = composition(x, node[k]);
eval(k, l, r);
return;
}
Apply(a, b, x, 2 * k + 1, l, (l + r) / 2);
Apply(a, b, x, 2 * k + 2, (l + r) / 2, r);
}
void eval(int k, int l, int r) {
if (r - l > 1) {
node[k * 2 + 1] = composition(node[k], node[k * 2 + 1]);
node[k * 2 + 2] = composition(node[k], node[k * 2 + 2]);
} else {
ar[k - n + 1] = mapping(node[k], ar[k - n + 1]);
}
node[k] = ID;
}
public:
DualSegmentTree() {}
DualSegmentTree(vector<S> &v) {
int sz = v.size();
n = 1;
while (n < sz) n *= 2;
node.resize(2 * n - 1, id());
ar.resize(sz);
for (int i = 0; i < sz; i++) {
ar[i] = v[i];
}
ID = id();
}
void apply(int l, int r, F x) {
Apply(l, r, x);
}
S get(int p) {
S ret = ar[p];
int l = p;
int r = p + 1;
p += (n - 1);
F f = node[p];
while (p > 0) {
p = (p - 1) / 2;
f = composition(node[p], f);
}
return mapping(f, ret);
}
F getf(int p) {
p += (n - 1);
F f = node[p];
while (p > 0) {
p = (p - 1) / 2;
f = composition(node[p], f);
}
return f;
}
};
#line 4 "verify/LibraryChecker/data-structure/segment-tree/RangeAffinePointGet.test.cpp"
#define MOD 998244353
using S = lint;
struct F {
lint a;
lint b;
};
S mapping(F f, S x) {
return ((x * f.a) % MOD + f.b) % MOD;
}
F composition(F f, F g) {
return {(f.a * g.a) % MOD, ((f.a * g.b) % MOD + f.b) % MOD};
}
F id() {
return {1, 0};
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
in(n, q);
vector<S> a(n);
in(a);
DualSegmentTree<S, F, mapping, composition, id> seg(a);
rep(i, q) {
int com;
in(com);
if (com == 0) {
int l, r;
lint b, c;
in(l, r, b, c);
seg.apply(l, r, {b, c});
} else {
int p;
in(p);
out(seg.get(p));
}
}
}