#abc273h. Ex - Inv(0,1)ving Insert(1,0)n

Ex - Inv(0,1)ving Insert(1,0)n

Score : 600600 points

问题陈述

我们有一个由整数对组成的序列 AA。初始时,A=((0,1),(1,0))A = ( (0, 1), (1, 0) )

你可以对序列 AA 进行任意多次(包括零次)以下操作:

  • 选择 相邻 的两个整数对 (a,b)(a, b)(c,d)(c, d),并在它们之间插入整数对 (a+c,b+d)(a + c, b + d)

对于一个由整数对组成的序列 TT,我们定义函数 f(T)f(T) 如下:

  • f(T)=f(T) = (使 TT 中每个元素都被包含在 AA 中所需的最小操作次数)。
    • 我们称“TT 中的每个元素都被包含在 AA 中”是指,对于 TT 中的所有元素 xxxx 都属于(由 AA 中元素构成的集合)。
  • 若不存在这样的操作,则令 f(T)=0f(T) = 0

存在一个由 NN 个整数对组成的序列 S=((a1,b1),(a2,b2),,(aN,bN))S = ((a_1, b_1), (a_2, b_2), \dots, (a_N, b_N)),其中 SS 中的所有元素两两不同。
SSN×(N+1)2\frac{N \times (N+1)}{2} 种可能的连续子数组 $S_{l,r}=((a_l,b_l),(a_{l+1},b_{l+1}),\dots,(a_r,b_r))$。求这些子数组中 f(Sl,r)f(S_{l,r}) 的和,取模 998244353998244353 后的结果。
形式上,要求解 $\displaystyle \sum^{N} _ {l=1} \sum^{N} _ {r=l} f(S_{l,r})$,并对结果取模 998244353998244353

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a sequence AA consisting of integer pairs. Initially, A=((0,1),(1,0))A = ( (0, 1), (1, 0) ).

You may perform the following operation on AA as many (possibly zero) times as you want:

  • choose adjacent two integer pairs (a,b)(a, b) and (c,d)(c, d), and insert (a+c,b+d)(a + c, b + d) between them.

For a sequence TT consisting of integer pairs, let us define f(T)f(T) as follows:

  • let f(T)=f(T) = (the minimum number of operations required to make every element of TT contained in AA).
    • We say that "every element of TT is contained in AA" if, for all elements xx contained in TT, xx is contained in (the set consisting of the elements contained in AA).
  • Here, if there are no such operations, let f(T)=0f(T) = 0.

There is a sequence S=((a1,b1),(a2,b2),,(aN,bN))S = ((a_1, b_1), (a_2, b_2), \dots, (a_N, b_N)) consisting of NN integer pairs. Here, all elements of SS are pairwise distinct.
There are N×(N+1)2\frac{N \times (N+1)}{2} possible consecutive subarrays $S_{l,r}=((a_l,b_l),(a_{l+1},b_{l+1}),\dots,(a_r,b_r))$ of SS. Find the sum, modulo 998244353998244353, of f(Sl,r)f(S_{l,r}) over those subarrays.
Formally, find $\displaystyle \sum^{N} _ {l=1} \sum^{N} _ {r=l} f(S_{l,r})$, modulo 998244353998244353.

Constraints

  • 1N1051 \le N \le 10^5
  • 0ai,bi1090 \le a_i,b_i \le 10^9
  • aiaja_i \neq a_j or bibjb_i \neq b_j, if iji \neq j.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

a2a_2 b2b_2

\dots

aNa_N bNb_N

Output

Print the answer as an integer.

Sample Input 1

7
1 2
3 7
3 5
0 0
1000000000 1
0 1
6 3

Sample Output 1

3511324
  • f(S1,1)=2f(S_{1,1})=2.
    • We can make $((0,1),(1,0)) \rightarrow ((0,1),(1,1),(1,0)) \rightarrow ((0,1),(1,2),(1,1),(1,0))$.
  • f(S1,2)=5f(S_{1,2})=5.
  • f(S1,3)=7f(S_{1,3})=7.
  • f(S2,2)=5f(S_{2,2})=5.
  • f(S2,3)=7f(S_{2,3})=7.
  • f(S3,3)=4f(S_{3,3})=4.
  • f(S5,5)=1000000000=109f(S_{5,5})=1000000000 = 10^9.
  • f(S5,6)=1000000000=109f(S_{5,6})=1000000000 = 10^9.
  • f(S6,6)=0f(S_{6,6})=0.
    • (0,1)(0, 1) is originally contained in AA.
  • f(Sl,r)=0f(S_{l,r})=0 for all Sl,rS_{l,r} not mentioned above.
    • We can prove that AA can never contain (0,0)(0,0) or (6,3)(6,3) regardless of operations.

Therefore, the sum of f(Sl,r)f(S_{l,r}) is 2000000030=2×109+302000000030 = 2 \times 10^9 + 30, whose remainder when divided by 998244353998244353 is 35113243511324.

update @ 2024/3/10 11:31:40