package main import ( "bufio" "fmt" "os" ) func main() { // https://yukicoder.me/problems/no/1891 // 给定一个长为2的幂次的数组 // 区间仿射变换,区间查询时每个下标异或上给定的数 in := bufio.NewReader(os.Stdin) out := bufio.NewWriter(os.Stdout) defer out.Flush() var n, q int fmt.Fscan(in, &n, &q) leaves := make([]S, n) for i := range leaves { fmt.Fscan(in, &leaves[i].mul, &leaves[i].add) } // RangeAffineRangeComposite seg := NewDisjointSparseTableXor(leaves) for i := 0; i < q; i++ { var start, end, indexXor, x int fmt.Fscan(in, &start, &end, &indexXor, &x) res := seg.Query(start, end, indexXor) fmt.Fprintln(out, (res.mul*x+res.add)%MOD) } } const MOD int = 998244353 type S = struct{ mul, add int } func (*DisjointSparseTableXor) e() S { return S{1, 0} } func (*DisjointSparseTableXor) op(a, b S) S { return S{a.mul * b.mul % MOD, (a.add*b.mul + b.add) % MOD} } type DisjointSparseTableXor struct { log int data [][]S } // DisjointSparseTableXor 支持半群的区间静态查询. // op:只需要满足结合律 op(op(a,b),c) = op(a,op(b,c)). // 区间查询时下标可以异或上 indexXor. // !nums 的长度必须要是2的幂. func NewDisjointSparseTableXor(nums []S) *DisjointSparseTableXor { res := &DisjointSparseTableXor{} n := len(nums) log := 0 for 1<= end { break } if start&(1< b { return a } return b }