#5116. Two Sequence Queries

0

Two Sequence Queries

Two Sequence Queries

题目描述

You are given sequences of length NN, A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) and B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N).
You are also given QQ queries to process in order. There are three types of queries:

1lrx1 l r x : Add xx to each of Al,Al+1,…,ArA_l, A_{l+1}, \ldots, A_r. 2lrx2 l r x : Add xx to each of Bl,Bl+1,…,BrB_l, B_{l+1}, \ldots, B_r. 3lr3 l r : Print the remainder of ∑i=lr(Ai×Bi)\displaystyle\sum_{i=l}^r (A_i\times B_i) when divided by 998244353998244353.

输入格式

The input is given from Standard Input in the following format. Here, queryi\mathrm{query}_i (1≤i≤Q)(1\leq i\leq Q) is the ii-th query to be processed. NN QQ A1A_1 A2A_2 …\ldots ANA_N B1B_1 B2B_2 …\ldots BNB_N query1\mathrm{query}_1 query2\mathrm{query}_2 ⋮\vdots queryQ\mathrm{query}_Q

Each query is given in one of the following formats: 11 ll rr xx

22 ll rr xx

33 ll rr

输出格式

If there are KK queries of the third type, print KK lines.
The ii-th line (1≤i≤K1\leq i\leq K) should contain the output for the ii-th query of the third type.

5 6
1 3 5 6 8
3 1 2 1 2
3 1 3
1 2 5 3
3 1 3
1 1 3 1
2 5 5 2
3 1 5
16
25
84
2 3
1000000000 1000000000
1000000000 1000000000
3 1 1
1 2 2 1000000000
3 1 2
716070898
151723988

提示

1≤N,Q≤2×1051\leq N,Q\leq 2\times 10^5 0≤Ai,Bi≤1090\leq A_i,B_i\leq 10^9 1≤l≤r≤N1\leq l\leq r\leq N 1≤x≤1091\leq x\leq 10^9 All input values are integers. There is at least one query of the third type.Initially, A=(1,3,5,6,8)A=(1,3,5,6,8) and B=(3,1,2,1,2)B=(3,1,2,1,2). The queries are processed in the following order:

For the first query, print (1×3)+(3×1)+(5×2)=16(1\times 3)+(3\times 1)+(5\times 2)=16 modulo 998244353998244353, which is 1616. For the second query, add 33 to A2,A3,A4,A5A_2,A_3,A_4,A_5. Now A=(1,6,8,9,11)A=(1,6,8,9,11). For the third query, print (1×3)+(6×1)+(8×2)=25(1\times 3)+(6\times 1)+(8\times 2)=25 modulo 998244353998244353, which is 2525. For the fourth query, add 11 to A1,A2,A3A_1,A_2,A_3. Now A=(2,7,9,9,11)A=(2,7,9,9,11). For the fifth query, add 22 to B5B_5. Now B=(3,1,2,1,4)B=(3,1,2,1,4). For the sixth query, print $(2\times 3)+(7\times 1)+(9\times 2)+(9\times 1)+(11\times 4)=84$ modulo 998244353998244353, which is 8484.

Thus, the first, second, and third lines should contain 1616, 2525, and 8484, respectively.
Make sure to print the sum modulo 998244353998244353 for the third type of query.

标签: AtCoder|abc357F

来源

AtCoder|abc357F