Narrower Passageway

시간 제한1초메모리 제한2048 MB

요약
각 열이 1/2 확률로 안개에 덮이고, 안개가 없는 최대 연속 구간마다 정의된 강도의 합의 기댓값을 998244353으로 나눈 나머지를 구한다.
난이도

어려움10점 중 9점

유형
확률, 동적 계획법, 조합론, 분할 정복
정답자
아직 제출이 없습니다

문제

You are a strategist of The ICPC Kingdom. You received an intel that there will be monster attacks on a narrow passageway near the kingdom. The narrow passageway can be represented as a grid with 22 rows (numbered from 11 to 22) and NN columns (numbered from 11 to NN). Denote (r,c)(r, c) as the cell in row rr and column cc. A soldier with a power of P_r,cP\_{r,c} is assigned to protect (r,c)(r, c) every single day.

It is known that the passageway is very foggy. Within a day, each column in the passageway has a 5050\\% chance of being covered in fog. If a column is covered in fog, the two soldiers assigned to that column are not deployed that day. Otherwise, the assigned soldiers will be deployed.

Define a connected area \[u,v]\[u, v] (u≤vu ≤ v) as a maximal set of consecutive columns from uu to vv (inclusive) such that each column in the set is not covered in fog. The following illustration is an example of connected areas. The grayed cells are cells covered in fog. There are 44 connected areas: \[1,2]\[1, 2], \[4,6]\[4, 6], \[9,9]\[9, 9], and \[11,11]\[11, 11].

The strength of a connected area \[u,v]\[u, v] can be calculated as follows. Let m_1m\_1 and m_2m\_2 be the maximum power of the soldiers in the first and second rows of the connected area, respectively. Formally, m_r=max⁡(P_r,u,P_r,u+1,…,P_r,v)m\_r = \max(P\_{r,u}, P\_{r,u+1}, \dots , P\_{r,v}) for r∈1,2r \in \\{1, 2\\}. If m_1=m_2m\_1 = m\_2, then the strength is 00. Otherwise, the strength is min⁡(m_1,m_2)\min(m\_1, m\_2).

The total strength of the deployment is the sum of the strengths for all connected areas. Determine the expected total strength of the deployment on any single day.

입력

The first line consists of an integer NN (1≤N≤100,0001 ≤ N ≤ 100\\, 000).

Each of the next two lines consists of NN integers P_r,cP\_{r,c} (1≤P_r,c≤200,0001 ≤ P\_{r,c} ≤ 200\\, 000).

출력

Let M=998,244,353M = 998\\, 244\\, 353. It can be shown that the expected total strength can be expressed as an irreducible fraction xy\frac{x}{y} such that xx and yy are integers and y≢0(modM)y \not\equiv 0 \pmod M. Output an integer kk in a single line such that 0≤k<M0 ≤ k < M and k⋅y≡x(modM)k \cdot y \equiv x \pmod M.

예제2

  1. 예제 1

    입력
    3
    8 4 5
    5 4 8
    
    예상 출력
    249561092
    
  2. 예제 2

    입력
    5
    10 20 5 8 5
    5 20 7 5 8
    
    예상 출력
    811073541