Total Area of Bounding Boxes

AtCoder
IDarc201_e
Time3000ms
Memory256MB
Difficulty
There are $N$ points numbered $1,2, \dots, N$ on the $2$\-dimensional plane. The coordinates of point $i$ are $(i,Y_i)$. In this problem, it is guaranteed that $Y=(Y_1,Y_2,\dots ,Y_N)$ is a permutation of $(1,2, \dots ,N)$. Find the sum of the areas of bounding boxes for all subsets $S$ of $\lbrace \texttt{point}\,1,\texttt{point}\,2,\dots ,\texttt{point}\,N \rbrace$ with at least $2$ elements, modulo $998244353$. The bounding box for $S$ refers to the minimum area rectangle with sides parallel to the $x$\-axis that contains all points in $S$ inside or on the boundary. ## Constraints * $2 \le N \le 2 \times 10^5$ * $Y$ is a permutation of $(1,2, \dots ,N)$. * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $Y_1$ $Y_2$ $\ldots$ $Y_N$ [samples]
Samples
Input #1
4
2 3 1 4
Output #1
50

Each subset and the area of its bounding box are shown in the figure below. Output the sum of areas, which is $50$. ![image](https://img.atcoder.jp/arc201/d0a42940efeb582795eb4766786ddd68.png)
Input #2
26
6 14 8 19 13 25 26 22 7 3 16 15 11 24 1 12 20 23 5 17 9 2 21 10 4 18
Output #2
575187918
API Response (JSON)
{
  "problem": {
    "name": "Total Area of Bounding Boxes",
    "description": {
      "content": "There are $N$ points numbered $1,2, \\dots, N$ on the $2$\\-dimensional plane. The coordinates of point $i$ are $(i,Y_i)$. In this problem, it is guaranteed that $Y=(Y_1,Y_2,\\dots ,Y_N)$ is a permutatio",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc201_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ points numbered $1,2, \\dots, N$ on the $2$\\-dimensional plane. The coordinates of point $i$ are $(i,Y_i)$. In this problem, it is guaranteed that $Y=(Y_1,Y_2,\\dots ,Y_N)$ is a permutatio...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments