Counting Rectangles

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

For two arrays of integers AA of size NN and BB of size MM, we define a grid G(A,B)G(A, B) of size N×MN \times M, where cell (i,,j)(i,\\, j) is colored black if 0A_i+B_j0 \le A\_i + B\_j and white otherwise.

We also define F(A,B)F(A, B) as the number of black rectangles inside G(A,B)G(A, B), where each cell of G(A,B)G(A, B) is either entirely included in or disjoint with the rectangle.

In other words, F(A,B)F(A, B) is equal to the number of tuples (l_1,,r_1,,l_2,,r_2)(l\_1,\\, r\_1,\\, l\_2,\\, r\_2) such that 1l_1r_1N1 \le l\_1 \le r\_1 \le N, 1l_2r_2M1 \le l\_2 \le r\_2 \le M and each cell (i,, j)(i,\\,  j) in G(A,B)G(A, B) is colored black for all ii, jj such that l_1ir_1l\_1 \le i \le r\_1, l_2jr_2l\_2 \le j \le r\_2.

Initially, only A_1A\_1 and B_1B\_1 are given.

Then, you should process following QQ queries:

  • 0 vv: append vv to current array AA.
  • 1 vv: append vv to current array AA. Then, print F(A,B)mod998,244,353F(A, B)\bmod 998\\,244\\,353.
  • 2 vv: append vv to current array BB.
  • 3 vv: append vv to current array BB. Then, print F(A,B)mod998,244,353F(A, B)\bmod 998\\,244\\,353.

입력

The first line contains one integer QQ.

The second line contains two space-separated integers, A_1A\_1 and B_1B\_1.

Each of the following QQ lines contains two space-separated integers denoting the queries in the described form.

출력

For each query of types 1 and 3, output a single integer denoting the answer to that query. Each answer should go on its own line.

제한

Let NN be the size of array AA after processing all queries, and MM be the size of array BB after processing all queries.

  • 1N250,0001 \le N \le 250\\,000
  • 1M250,0001 \le M \le 250\\,000
  • 1Q=N+M21 \le Q = N + M - 2
  • 109A_i109-10^9 \le A\_{i} \le 10^9 (1iN)(1 \le i \le N)
  • 109B_i109-10^9 \le B\_{i} \le 10^9 (1iM)(1 \le i \le M)
  • The last query has a type of 1 or 3.