|
| 1 | +#define PROBLEM \ |
| 2 | + "https://judge.yosupo.jp/problem/queue_operate_all_composite" |
| 3 | +#include "../template.hpp" |
| 4 | +#include "../../../library/contest/random.hpp" |
| 5 | +#include "../../../library/data_structures_[l,r]/disjoint_rmq.hpp" |
| 6 | +#include "../../../library/data_structures_[l,r)/seg_tree.hpp" |
| 7 | +const int mod = 998'244'353; |
| 8 | +int main() { |
| 9 | + cin.tie(0)->sync_with_stdio(0); |
| 10 | + int q; |
| 11 | + cin >> q; |
| 12 | + vector<array<int, 3>> queries(q); |
| 13 | + vector<array<int, 2>> init; |
| 14 | + for (int i = 0; i < q; i++) { |
| 15 | + int type; |
| 16 | + cin >> type; |
| 17 | + if (type == 0) { |
| 18 | + int a, b; |
| 19 | + cin >> a >> b; |
| 20 | + queries[i] = {type, a, b}; |
| 21 | + init.push_back({a, b}); |
| 22 | + } else if (type == 1) { |
| 23 | + queries[i] = {type, -1, -1}; |
| 24 | + } else { |
| 25 | + int x; |
| 26 | + cin >> x; |
| 27 | + queries[i] = {type, x, -1}; |
| 28 | + } |
| 29 | + } |
| 30 | + auto f = [&](const array<int, 2>& l, |
| 31 | + const array<int, 2>& r) -> array<int, 2> { |
| 32 | + return {int(1LL * l[0] * r[0] % mod), |
| 33 | + int((1LL * r[0] * l[1] + r[1]) % mod)}; |
| 34 | + }; |
| 35 | + const array<int, 2> unit = {1, 0}; |
| 36 | + tree st(ssize(init), unit, f); |
| 37 | + for (int i = 0; i < ssize(init); i++) |
| 38 | + st.update(i, init[i]); |
| 39 | + disjoint_rmq rmq(init, f); |
| 40 | + int l = 0, r = 0; //[l,r) |
| 41 | + for (int i = 0; i < q; i++) { |
| 42 | + int type = queries[i][0]; |
| 43 | + if (type == 0) { |
| 44 | + r++; |
| 45 | + } else if (type == 1) { |
| 46 | + l++; |
| 47 | + } else { |
| 48 | + int x = queries[i][1]; |
| 49 | + assert(l <= r); |
| 50 | + int which = rnd(0, 2); |
| 51 | + st.max_right(l, r, |
| 52 | + [&](int m, const array<int, 2>& val) -> bool { |
| 53 | + assert(l < m && m <= r); |
| 54 | + assert(val == rmq.query(l, m - 1)); |
| 55 | + if (which == 0) return 0; |
| 56 | + else if (which == 1) return 1; |
| 57 | + else return rnd(0, 1); |
| 58 | + }); |
| 59 | + st.min_left(l, r, |
| 60 | + [&](int m, const array<int, 2>& val) -> bool { |
| 61 | + assert(l <= m && m < r); |
| 62 | + assert(val == rmq.query(m, r - 1)); |
| 63 | + if (which == 0) return 0; |
| 64 | + else if (which == 1) return 1; |
| 65 | + else return rnd(0, 1); |
| 66 | + }); |
| 67 | + if (l == r) cout << x << '\n'; |
| 68 | + else { |
| 69 | + array<int, 2> line = rmq.query(l, r - 1); |
| 70 | + cout << (1LL * line[0] * x + line[1]) % mod |
| 71 | + << '\n'; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + return 0; |
| 76 | +} |
0 commit comments